Skip to content

Commit

Permalink
Make element provider tests use XmlPullParserKind
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Jan 28, 2021
1 parent b4e89c6 commit b954bd5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Fernando Ramirez
* Copyright 2017 Fernando Ramirez, 2021 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,13 +19,13 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.test.util.SmackTestUtil;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smackx.avatar.element.DataExtension;
import org.jivesoftware.smackx.avatar.provider.DataProvider;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

public class DataExtensionTest extends SmackTestSuite {

Expand All @@ -35,14 +35,14 @@ public class DataExtensionTest extends SmackTestSuite {
+ "</data>";
// @formatter:on

@Test
public void checkDataExtensionParse() throws Exception {
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void checkDataExtensionParse(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
byte[] data = Base64.decode("qANQR1DBwU4DX7jmYZnnfe32");
DataExtension dataExtension = new DataExtension(data);
assertEquals(dataExtensionExample, dataExtension.toXML().toString());

XmlPullParser parser = PacketParserUtils.getParserFor(dataExtensionExample);
DataExtension dataExtensionFromProvider = new DataProvider().parse(parser);
DataExtension dataExtensionFromProvider = SmackTestUtil.parse(dataExtensionExample, DataProvider.class, parserKind);
assertEquals(Base64.encodeToString(data), Base64.encodeToString(dataExtensionFromProvider.getData()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Fernando Ramirez
* Copyright 2017 Fernando Ramirez, 2021 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,12 +25,13 @@
import java.util.List;
import java.util.Map;

import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.test.util.SmackTestUtil;
import org.jivesoftware.smackx.avatar.element.MetadataExtension;
import org.jivesoftware.smackx.avatar.provider.MetadataProvider;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

public class MetadataExtensionTest {

Expand Down Expand Up @@ -87,8 +88,9 @@ public class MetadataExtensionTest {
+ "</pointer>"
+ "</metadata>";

@Test
public void checkMetadataExtensionParse() throws Exception {
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void checkMetadataExtensionParse(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
String id = "357a8123a30844a3aa99861b6349264ba67a5694";
URL url = new URL("http://avatars.example.org/happy.gif");
long bytes = 23456;
Expand All @@ -103,8 +105,8 @@ public void checkMetadataExtensionParse() throws Exception {
MetadataExtension metadataExtension = new MetadataExtension(infos);
assertEquals(metadataExtensionExample, metadataExtension.toXML().toString());

XmlPullParser parser = PacketParserUtils.getParserFor(metadataExtensionExample);
MetadataExtension metadataExtensionFromProvider = new MetadataProvider().parse(parser);
MetadataExtension metadataExtensionFromProvider = SmackTestUtil
.parse(metadataExtensionExample, MetadataProvider.class, parserKind);

assertEquals(id, metadataExtensionFromProvider.getInfoElements().get(0).getId());
assertEquals(url, metadataExtensionFromProvider.getInfoElements().get(0).getUrl());
Expand All @@ -120,10 +122,11 @@ public void checkEmptyMetadataExtensionParse() {
assertEquals(emptyMetadataExtensionExample, metadataExtension.toXML().toString());
}

@Test
public void checkSeveralInfosInMetadataExtension() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(metadataWithSeveralInfos);
MetadataExtension metadataExtensionFromProvider = new MetadataProvider().parse(parser);
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void checkSeveralInfosInMetadataExtension(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
MetadataExtension metadataExtensionFromProvider = SmackTestUtil
.parse(metadataWithSeveralInfos, MetadataProvider.class, parserKind);

MetadataInfo info1 = metadataExtensionFromProvider.getInfoElements().get(0);
MetadataInfo info2 = metadataExtensionFromProvider.getInfoElements().get(1);
Expand Down Expand Up @@ -151,10 +154,11 @@ public void checkSeveralInfosInMetadataExtension() throws Exception {
assertEquals(64, info3.getWidth().intValue());
}

@Test
public void checkInfosAndPointersParse() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(metadataWithInfoAndPointers);
MetadataExtension metadataExtensionFromProvider = new MetadataProvider().parse(parser);
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void checkInfosAndPointersParse(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
MetadataExtension metadataExtensionFromProvider = SmackTestUtil
.parse(metadataWithInfoAndPointers, MetadataProvider.class, parserKind);

MetadataInfo info = metadataExtensionFromProvider.getInfoElements().get(0);
assertEquals("111f4b3c50d7b0df729d299bc6f8e9ef9066971f", info.getId());
Expand Down

0 comments on commit b954bd5

Please sign in to comment.