Skip to content
Snippets Groups Projects
Commit 5c176a38 authored by Thiemo Belmega's avatar Thiemo Belmega
Browse files

Implement REST Interface to get all the existing Objects of a resource type

parent 29da3f77
No related branches found
No related tags found
No related merge requests found
package de.unipotsdam.cs.toolup.util;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.Collection;
public class AssertionUtil {
public static <T> void assertContainsAll(Collection<T> expectedCollection, Collection<? extends T> actualCollection) {
if (expectedCollection == null && actualCollection == null) {
return;
}
if (expectedCollection == null ^ actualCollection == null) {
throw new AssertionError("Expected: " + expectedCollection + "\n but was: " + actualCollection);
}
if (!expectedCollection.containsAll(actualCollection)) {
String expected = ToStringBuilder.reflectionToString(expectedCollection);
String actual = ToStringBuilder.reflectionToString(actualCollection);
throw new AssertionError("Expected: " + expected + "\n but was: " + actual);
}
}
public static <T> void assertCollectionEquals(Collection<T> expectedCollection, Collection<T> actualCollection) {
if (expectedCollection == null && actualCollection == null) {
return;
}
if (expectedCollection == null ^ actualCollection == null) {
throw new AssertionError("Expected: " + expectedCollection + "\n but was: " + actualCollection);
}
if (expectedCollection.size() != actualCollection.size()) {
throw new AssertionError("Expected size " + expectedCollection.size() + "\n but was: " + actualCollection.size());
}
assertContainsAll(expectedCollection, actualCollection);
assertContainsAll(actualCollection, expectedCollection);
}
}
package de.unipotsdam.cs.toolup.util;
import org.testng.annotations.Test;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
public class AssertionUtilTest {
@Test(expectedExceptions = {AssertionError.class})
public void testThatCollectionDoesNotEqualCollection() {
//arrange
Collection<Integer> coll1 = new LinkedList<>();
coll1.add(5);
Collection<Integer> coll2 = new HashSet<>();
coll2.add(6);
//act
AssertionUtil.assertCollectionEquals(coll2, coll1);
//assert
}
@Test
public void testThatCollectionEqualsCollection() {
//arrange
Collection<Integer> coll1 = new LinkedList<>();
coll1.add(5);
Collection<Integer> coll2 = new HashSet<>();
coll2.add(5);
//act
AssertionUtil.assertCollectionEquals(coll2, coll1);
//assert
}
@Test
public void testThatListEqualsSet() {
//arrange
LinkedList<Integer> coll1 = new LinkedList<>();
coll1.add(5);
HashSet<Integer> coll2 = new HashSet<>();
coll2.add(5);
//act
AssertionUtil.assertCollectionEquals(coll2, coll1);
//assert
}
}
package de.unipotsdam.cs.toolup.ws.resource;
import de.unipotsdam.cs.toolup.ws.beans.ApplicationBean;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Collection;
import static de.unipotsdam.cs.toolup.model.BusinessObjectTest.APPLICATION_TEST_ID_1;
import static de.unipotsdam.cs.toolup.model.BusinessObjectTest.APPLICATION_TEST_ID_2;
import static org.testng.Assert.assertEquals;
public class ApplicationResourceTest {
@Test
public void testThatApplicationResourceGETWithOutIdReturnsAllApplications() throws Exception {
//arrange
Collection<ApplicationBean> expectedApps = Arrays.asList(
ApplicationBean.getBean(APPLICATION_TEST_ID_1),
ApplicationBean.getBean(APPLICATION_TEST_ID_2)
);
ApplicationResource appRes = new ApplicationResource();
//act
Collection<ApplicationBean> apps = appRes.getAll();
//assert
assertEquals(expectedApps, apps);
}
}
package de.unipotsdam.cs.toolup.ws.resource;
import de.unipotsdam.cs.toolup.ws.beans.CategoryBean;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Collection;
import static de.unipotsdam.cs.toolup.model.BusinessObjectTest.CATEGORY_TEST_ID_11;
import static de.unipotsdam.cs.toolup.model.BusinessObjectTest.CATEGORY_TEST_ID_12;
import static org.testng.Assert.assertEquals;
public class CategoryResourceTest {
@Test
public void testThatCategoryResourceGETWithOutIdReturnsAllCategories() throws Exception {
//arrange
Collection<CategoryBean> expectedCats = Arrays.asList(
CategoryBean.getBean(CATEGORY_TEST_ID_11),
CategoryBean.getBean(CATEGORY_TEST_ID_12)
);
CategoryResource catRes = new CategoryResource();
//act
Collection<CategoryBean> cats = catRes.getAll();
//assert
assertEquals(expectedCats, cats);
}
}
package de.unipotsdam.cs.toolup.ws.resource;
import de.unipotsdam.cs.toolup.util.AssertionUtil;
import de.unipotsdam.cs.toolup.ws.beans.FeatureBean;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Collection;
import static de.unipotsdam.cs.toolup.model.BusinessObjectTest.FEATURE_TEST_ID_21;
import static de.unipotsdam.cs.toolup.model.BusinessObjectTest.FEATURE_TEST_ID_22;
public class FeatureResourceTest {
@Test
public void testThatFeatureResourceGETWithOutIdReturnsAllFeatures() throws Exception {
//arrange
Collection<FeatureBean> expectedFeats = Arrays.asList(
FeatureBean.getBean(FEATURE_TEST_ID_21),
FeatureBean.getBean(FEATURE_TEST_ID_22)
);
FeatureResource featRes = new FeatureResource();
//act
Collection<FeatureBean> feats = featRes.getAll();
//assert
AssertionUtil.assertCollectionEquals(expectedFeats, feats);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment