diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/numitem/AllTests.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/numitem/AllTests.java index c406312..5daafad 100644 --- a/src/test/java/daxi/moe/test/mem/obj2mod/linear/numitem/AllTests.java +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/numitem/AllTests.java @@ -29,7 +29,7 @@ import java.util.logging.Logger; * @author indroneel */ -@DisplayName("[Object2Model] Linear data retrieval tests") +@DisplayName("[Object2Model] Linear data retrieval tests with integer items") public class AllTests extends MemObj2ModTests { private static final Logger L = Logger.getLogger(AllTests.class.getName()); diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/AllTests.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/AllTests.java new file mode 100644 index 0000000..d4f865b --- /dev/null +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/AllTests.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) DuxTechnica + * + * Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not + * use this file except in compliance with the License. You may obtain a copy of the License by + * contacting: + * + * Dux Technica, contact@duxtechnica.com + * + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package daxi.moe.test.mem.obj2mod.linear.objitem; + +import daxi.moe.model.AnyData; +import daxi.moe.model.LinearData; +import daxi.moe.test.mem.obj2mod.MemObj2ModTests; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +import java.util.Set; +import java.util.logging.Logger; + +/** + * @author indroneel + */ + +@DisplayName("[Object2Model] Linear data retrieval tests with custom object items") +public class AllTests extends MemObj2ModTests { + + private static final Logger L = Logger.getLogger(AllTests.class.getName()); + + @Test + @Order(1) + @DisplayName("[Object2Model] Array of custom objects is retrieved correctly") + public void test01() { + ObjArrayRoot srcObj = new ObjArrayRoot(); + Assertions.assertDoesNotThrow(() -> retrieve(srcObj)); + + AnyData data = getModel(); + Assertions.assertNotNull(data); + + AnyData alData = data.asMapped().get("values"); + Assertions.assertNotNull(alData); + + LinearData ldata = alData.asLinear(); + Assertions.assertNotNull(ldata); + + Assertions.assertEquals(3, ldata.size()); + + Assertions.assertEquals("value1", + ldata.get(0).asMapped().get("member1").asSimple().getString()); + Assertions.assertEquals("value2", + ldata.get(1).asMapped().get("member1").asSimple().getString()); + Assertions.assertEquals("value3", + ldata.get(2).asMapped().get("member1").asSimple().getString()); + + Assertions.assertEquals(1, + ldata.get(0).asMapped().get("member2").asSimple().getNumber().intValue()); + Assertions.assertEquals(2, + ldata.get(1).asMapped().get("member2").asSimple().getNumber().intValue()); + Assertions.assertEquals(3, + ldata.get(2).asMapped().get("member2").asSimple().getNumber().intValue()); + } + + @Test + @Order(2) + @DisplayName("[Object2Model] List of custom objects is retrieved correctly") + public void test02() { + ObjListRoot srcObj = new ObjListRoot(); + Assertions.assertDoesNotThrow(() -> retrieve(srcObj)); + + AnyData data = getModel(); + Assertions.assertNotNull(data); + + AnyData alData = data.asMapped().get("values"); + Assertions.assertNotNull(alData); + + LinearData ldata = alData.asLinear(); + Assertions.assertNotNull(ldata); + + Assertions.assertEquals(3, ldata.size()); + + Assertions.assertEquals("value1", + ldata.get(0).asMapped().get("member1").asSimple().getString()); + Assertions.assertEquals("value2", + ldata.get(1).asMapped().get("member1").asSimple().getString()); + Assertions.assertEquals("value3", + ldata.get(2).asMapped().get("member1").asSimple().getString()); + + Assertions.assertEquals(1, + ldata.get(0).asMapped().get("member2").asSimple().getNumber().intValue()); + Assertions.assertEquals(2, + ldata.get(1).asMapped().get("member2").asSimple().getNumber().intValue()); + Assertions.assertEquals(3, + ldata.get(2).asMapped().get("member2").asSimple().getNumber().intValue()); + } + + @Test + @Order(3) + @DisplayName("[Object2Model] Set of custom objects is retrieved correctly") + public void test03() { + ObjSetRoot srcObj = new ObjSetRoot(); + Assertions.assertDoesNotThrow(() -> retrieve(srcObj)); + + AnyData data = getModel(); + Assertions.assertNotNull(data); + + AnyData alData = data.asMapped().get("values"); + Assertions.assertNotNull(alData); + + LinearData ldata = alData.asLinear(); + Assertions.assertNotNull(ldata); + + Assertions.assertEquals(3, ldata.size()); + + Set expStrValues = Set.of("value1", "value2", "value3"); + Set expIntValues = Set.of(1, 2, 3); + for (int i = 0; i < 3; i++) { + Assertions.assertTrue(expStrValues.contains( + ldata.get(i).asMapped().get("member1").asSimple().getString())); + Assertions.assertTrue(expIntValues.contains( + ldata.get(i).asMapped().get("member2").asSimple().getNumber().intValue())); + } + } +} diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjArrayRoot.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjArrayRoot.java new file mode 100644 index 0000000..829ddc8 --- /dev/null +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjArrayRoot.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) DuxTechnica + * + * Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not + * use this file except in compliance with the License. You may obtain a copy of the License by + * contacting: + * + * Dux Technica, contact@duxtechnica.com + * + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package daxi.moe.test.mem.obj2mod.linear.objitem; + +import daxi.moe.app.MapTo; + +/** + * @author indroneel + */ + +public class ObjArrayRoot { + + private final SimpleObj[] values; + + public ObjArrayRoot() { + values = new SimpleObj[]{ + new SimpleObj("value1", 1), + new SimpleObj("value2", 2), + new SimpleObj("value3", 3) + }; + } + + @MapTo("values") + private SimpleObj[] _values() { + return values; + } +} diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjListRoot.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjListRoot.java new file mode 100644 index 0000000..9bed372 --- /dev/null +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjListRoot.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) DuxTechnica + * + * Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not + * use this file except in compliance with the License. You may obtain a copy of the License by + * contacting: + * + * Dux Technica, contact@duxtechnica.com + * + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package daxi.moe.test.mem.obj2mod.linear.objitem; + +import daxi.moe.app.MapTo; + +import java.util.List; + +/** + * @author indroneel + */ + +public class ObjListRoot { + + private final List values; + + public ObjListRoot() { + values = List.of( + new SimpleObj("value1", 1), + new SimpleObj("value2", 2), + new SimpleObj("value3", 3) + ); + } + + @MapTo("values") + private List _values() { + return values; + } +} diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjSetRoot.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjSetRoot.java new file mode 100644 index 0000000..dcd040b --- /dev/null +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/ObjSetRoot.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) DuxTechnica + * + * Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not + * use this file except in compliance with the License. You may obtain a copy of the License by + * contacting: + * + * Dux Technica, contact@duxtechnica.com + * + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package daxi.moe.test.mem.obj2mod.linear.objitem; + +import daxi.moe.app.MapTo; + +import java.util.Set; + +/** + * @author indroneel + */ + +public class ObjSetRoot { + + private final Set values; + + public ObjSetRoot() { + values = Set.of( + new SimpleObj("value1", 1), + new SimpleObj("value2", 2), + new SimpleObj("value3", 3) + ); + } + + @MapTo("values") + private Set _values() { + return values; + } +} diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/SimpleObj.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/SimpleObj.java new file mode 100644 index 0000000..e4d3985 --- /dev/null +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/objitem/SimpleObj.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) DuxTechnica + * + * Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not + * use this file except in compliance with the License. You may obtain a copy of the License by + * contacting: + * + * Dux Technica, contact@duxtechnica.com + * + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package daxi.moe.test.mem.obj2mod.linear.objitem; + +import daxi.moe.app.MapTo; + +/** + * @author indroneel + */ + +public class SimpleObj { + + private final String member1; + private final int member2; + + public SimpleObj(String val1, int val2) { + member1 = val1; + member2 = val2; + } + + @MapTo("member1") + private String _member1() { + return member1; + } + + @MapTo("member2") + private int _member2() { + return member2; + } +} diff --git a/src/test/java/daxi/moe/test/mem/obj2mod/linear/stritem/AllTests.java b/src/test/java/daxi/moe/test/mem/obj2mod/linear/stritem/AllTests.java index 2eccc6e..0a1bf9b 100644 --- a/src/test/java/daxi/moe/test/mem/obj2mod/linear/stritem/AllTests.java +++ b/src/test/java/daxi/moe/test/mem/obj2mod/linear/stritem/AllTests.java @@ -29,7 +29,7 @@ import java.util.logging.Logger; * @author indroneel */ -@DisplayName("[Object2Model] Linear data retrieval tests") +@DisplayName("[Object2Model] Linear data retrieval tests with string items") public class AllTests extends MemObj2ModTests { private static final Logger L = Logger.getLogger(AllTests.class.getName());