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

JSON representation should contain super and subcategories

parent dcf1d359
No related branches found
No related tags found
No related merge requests found
......@@ -8,13 +8,12 @@ import static de.unipotsdam.cs.toolup.database.DatabaseController.TABLE_NAME_APP
public class Category extends BusinessObject {
private String superCategory;
private Collection<String> subCategories;
private String superCategory = "";
private Collection<String> subCategories = new HashSet<>();
public Category(String uuid, String title, String description, Set<String> relatedApplications) {
super(uuid, title, description);
this.relations.put(TABLE_NAME_APPLICATION, relatedApplications);
this.subCategories = new HashSet<>();
}
public Category(String uuid) {
......@@ -40,4 +39,16 @@ public class Category extends BusinessObject {
public void addSubCategories(Collection<String> subcategories) {
this.subCategories.addAll(subcategories);
}
@Override
public boolean equalsInAllProperties(BusinessObject anOtherBO) {
if (!(anOtherBO instanceof Category)) return false;
Category anotherCat = (Category) anOtherBO;
if (!this.getSuperCategory().equals(anotherCat.getSuperCategory())) return false;
if (!this.getSubCategories().equals(anotherCat.getSubCategories())) return false;
return super.equalsInAllProperties(anOtherBO);
}
}
......@@ -8,6 +8,7 @@ import org.json.JSONObject;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
......@@ -22,6 +23,7 @@ public class BusinessObjectTest {
public static final String CATEGORY_TEST_ID_11 = "category-test_id_11";
public static final String CATEGORY_TEST_ID_12 = "category-test_id_12";
public static final String CATEGORY_TEST_ID_13 = "category-test_id_13";
public static final String CATEGORY_TEST_ID_19 = "category-test_id_19";
public static final String PROVIDE_SAMPLE_IDS = "provideSampleIds";
public static final String PROVIDE_BOS_TO_COMPARE = "provideBOsToCompare";
public static final String PROVIDE_BUSINESS_OBJECTS = "provideBusinessObjects";
......@@ -183,7 +185,9 @@ public class BusinessObjectTest {
BusinessObject app1 = new Application(APPLICATION_TEST_ID_1, APPLICATION_TESTTITLE_1, APPLICATION_TESTDESCRIPTION_1, relatedCats, relatedFeats);
BusinessObject feat1 = new Feature(FEATURE_TEST_ID_21, FEATURE_TESTTITLE_21, FEATURE_TESTDESCRIPTION_21, relatedApps);
BusinessObject cat1 = new Category(CATEGORY_TEST_ID_11, CATEGORY_TESTTITLE_11, CATEGORY_TESTDESCRIPTION_11, relatedApps);
Category cat1 = new Category(CATEGORY_TEST_ID_11, CATEGORY_TESTTITLE_11, CATEGORY_TESTDESCRIPTION_11, relatedApps);
cat1.setSuperCategory(CATEGORY_TEST_ID_13);
cat1.addSubCategories(Arrays.asList(CATEGORY_TEST_ID_19));
JSONObject expectedJsonApp = new JSONObject(FileUtil.readFile(FILENAME_TEST_APP_JSON));
JSONObject expectedJsonFeat = new JSONObject(FileUtil.readFile(FILENAME_TEST_FEAT_JSON));
......
......@@ -2,6 +2,7 @@
"id": "category-test_id_11",
"title": "Cloud Speicher",
"description": "Cloud Speicher Description",
"supercategory": "category-test_id_13",
"applications": [
{
"id": "application-test_id_1"
......@@ -9,5 +10,10 @@
{
"id": "application-test_id_2"
}
],
"subcategories": [
{
"id": "category-test_id_19"
}
]
}
\ No newline at end of file
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