EDBConverter { @SuppressWarnings("unchecked") public <T> T convertEDBObjectToModel(Class<T> model, EDBObject object) { return (T) convertEDBObjectToUncheckedModel(model, object); } EDBConverter(EngineeringDatabaseService edbService); @SuppressWarnings("unchecked") T convertEDBObjectToModel(Class<T> model, EDBObject object); List<T> convertEDBObjectsToModelObjects(Class<T> model, List<EDBObject> objects); ConvertedCommit convertEKBCommit(EKBCommit commit); List<EDBObject> convertModelsToEDBObjects(List<OpenEngSBModel> models, ConnectorInformation info); List<EDBObject> convertModelToEDBObject(Object model, ConnectorInformation info); static String getEntryNameForMapKey(String property, Integer index); static String getEntryNameForMapValue(String property, Integer index); static String getEntryNameForList(String property, Integer index); static String getEOReferenceStringFromAnnotation(OpenEngSBForeignKey key); static final String FILEWRAPPER_FILENAME_SUFFIX; static final String REFERENCE_PREFIX; }
@Test public void primitivePropertyConversion_toModel_works() { EDBObject object = new EDBObject("test"); object.putEDBObjectEntry(EDBConstants.MODEL_TYPE, PrimitivePropertiesModel.class.getName()); object.putEDBObjectEntry(EDBConstants.MODEL_OID, "test"); object.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); object.putEDBObjectEntry("id", "test"); object.putEDBObjectEntry("booleanByGet", true); object.putEDBObjectEntry("booleanByIs", true); object.putEDBObjectEntry("primitiveChar", Character.MAX_VALUE); object.putEDBObjectEntry("primitiveShort", Short.MAX_VALUE); object.putEDBObjectEntry("primitiveInt", Integer.MAX_VALUE); object.putEDBObjectEntry("primitiveLong", Long.MAX_VALUE); object.putEDBObjectEntry("primitiveFloat", Float.MAX_VALUE); object.putEDBObjectEntry("primitiveDouble", Double.MAX_VALUE); PrimitivePropertiesModel model = converter.convertEDBObjectToModel(PrimitivePropertiesModel.class, object); assertThat(model.getId(), is("test")); assertThat(model.getBooleanByGet(), is(true)); assertThat(model.isBooleanByIs(), is(true)); assertThat(model.getPrimitiveChar(), is(Character.MAX_VALUE)); assertThat(model.getPrimitiveShort(), is(Short.MAX_VALUE)); assertThat(model.getPrimitiveInt(), is(Integer.MAX_VALUE)); assertThat(model.getPrimitiveLong(), is(Long.MAX_VALUE)); assertThat(model.getPrimitiveFloat(), is(Float.MAX_VALUE)); assertThat(model.getPrimitiveDouble(), is(Double.MAX_VALUE)); }
@Test public void wrappedPropertyConversion_toModel_works() { EDBObject object = new EDBObject("test"); object.putEDBObjectEntry(EDBConstants.MODEL_TYPE, WrappedPropertiesModel.class.getName()); object.putEDBObjectEntry(EDBConstants.MODEL_OID, "test"); object.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); object.putEDBObjectEntry("id", "test"); object.putEDBObjectEntry("booleanByGet", true); object.putEDBObjectEntry("booleanByIs", true); object.putEDBObjectEntry("wrappedChar", Character.MAX_VALUE); object.putEDBObjectEntry("wrappedShort", Short.MAX_VALUE); object.putEDBObjectEntry("wrappedInt", Integer.MAX_VALUE); object.putEDBObjectEntry("wrappedLong", Long.MAX_VALUE); object.putEDBObjectEntry("wrappedFloat", Float.MAX_VALUE); object.putEDBObjectEntry("wrappedDouble", Double.MAX_VALUE); WrappedPropertiesModel model = converter.convertEDBObjectToModel(WrappedPropertiesModel.class, object); assertThat(model.getId(), is("test")); assertThat(model.getBooleanByGet(), is(true)); assertThat(model.isBooleanByIs(), is(true)); assertThat(model.getWrappedChar(), is(Character.MAX_VALUE)); assertThat(model.getWrappedShort(), is(Short.MAX_VALUE)); assertThat(model.getWrappedInt(), is(Integer.MAX_VALUE)); assertThat(model.getWrappedLong(), is(Long.MAX_VALUE)); assertThat(model.getWrappedFloat(), is(Float.MAX_VALUE)); assertThat(model.getWrappedDouble(), is(Double.MAX_VALUE)); }
@Test public void testEDBObjectToModelConversion_shouldWork() throws Exception { EDBObject object = new EDBObject("test"); object.putEDBObjectEntry(EDBConstants.MODEL_TYPE, TestModel.class.getName()); object.putEDBObjectEntry(EDBConstants.MODEL_OID, "test"); object.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); object.putEDBObjectEntry("id", "test"); object.putEDBObjectEntry("name", "testname"); object.putEDBObjectEntry("number", 42); object.putEDBObjectEntry("check", false); object.putEDBObjectEntry("check2", true); TestModel model = converter.convertEDBObjectToModel(TestModel.class, object); assertThat(model.getId(), is("test")); assertThat(model.getName(), is("testname")); assertThat(model.isCheck(), is(false)); assertThat(model.isCheck2(), is(true)); Object version = ModelWrapper.wrap(model).retrieveInternalModelVersion(); assertThat(version, notNullValue()); assertThat((Integer) version, is(1)); }
@Test public void testEDBObjectToRecursiveModelConversion_shouldWork() throws Exception { EDBObject root = new EDBObject("root"); root.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); root.putEDBObjectEntry(EDBConstants.MODEL_OID, "root"); root.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); root.putEDBObjectEntry("id", "root"); root.putEDBObjectEntry("child", "child1"); EDBObject child1 = new EDBObject("child1"); child1.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child1.putEDBObjectEntry(EDBConstants.MODEL_OID, "child1"); child1.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child1.putEDBObjectEntry("id", "child1"); child1.putEDBObjectEntry("child", "child2"); EDBObject child2 = new EDBObject("child2"); child2.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child2.putEDBObjectEntry(EDBConstants.MODEL_OID, "child2"); child2.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child2.putEDBObjectEntry("id", "child2"); child2.putEDBObjectEntry("child", "child3"); EDBObject child3 = new EDBObject("child3"); child3.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child3.putEDBObjectEntry(EDBConstants.MODEL_OID, "child3"); child3.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child3.putEDBObjectEntry("id", "child3"); when(mockedService.getObject(eq("child1"), anyLong())).thenReturn(child1); when(mockedService.getObject(eq("child2"), anyLong())).thenReturn(child2); when(mockedService.getObject(eq("child3"), anyLong())).thenReturn(child3); RecursiveModel mRoot = converter.convertEDBObjectToModel(RecursiveModel.class, root); assertThat(mRoot.getId(), is("root")); RecursiveModel mChild1 = mRoot.getChild(); assertThat(mChild1, notNullValue()); assertThat(mChild1.getId(), is("child1")); RecursiveModel mChild2 = mChild1.getChild(); assertThat(mChild2, notNullValue()); assertThat(mChild2.getId(), is("child2")); RecursiveModel mChild3 = mChild2.getChild(); assertThat(mChild3, notNullValue()); assertThat(mChild3.getId(), is("child3")); }
@Test public void testEDBObjectToRecursiveModelWithCompositionConversion_shouldWork() throws Exception { EDBObject root = new EDBObject("root"); root.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); root.putEDBObjectEntry(EDBConstants.MODEL_OID, "root"); root.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); root.putEDBObjectEntry("id", "root"); root.putEDBObjectEntry("children.0", "child1"); root.putEDBObjectEntry("children.1", "child2"); EDBObject child1 = new EDBObject("child1"); child1.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child1.putEDBObjectEntry(EDBConstants.MODEL_OID, "child1"); child1.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child1.putEDBObjectEntry("id", "child1"); child1.putEDBObjectEntry("children.0", "child3"); child1.putEDBObjectEntry("children.1", "child4"); EDBObject child2 = new EDBObject("child2"); child2.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child2.putEDBObjectEntry(EDBConstants.MODEL_OID, "child2"); child2.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child2.putEDBObjectEntry("id", "child2"); EDBObject child3 = new EDBObject("child3"); child3.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child3.putEDBObjectEntry(EDBConstants.MODEL_OID, "child3"); child3.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child3.putEDBObjectEntry("id", "child3"); EDBObject child4 = new EDBObject("child4"); child4.putEDBObjectEntry(EDBConstants.MODEL_TYPE, RecursiveModel.class.getName()); child4.putEDBObjectEntry(EDBConstants.MODEL_OID, "child4"); child4.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); child4.putEDBObjectEntry("id", "child4"); when(mockedService.getObject("child1")).thenReturn(child1); when(mockedService.getObject("child2")).thenReturn(child2); when(mockedService.getObject("child3")).thenReturn(child3); when(mockedService.getObject("child4")).thenReturn(child4); RecursiveModel mRoot = converter.convertEDBObjectToModel(RecursiveModel.class, root); RecursiveModel mChild1; RecursiveModel mChild2; RecursiveModel mChild3; RecursiveModel mChild4; List<RecursiveModel> rootChildren; List<RecursiveModel> child1Children; assertThat(mRoot.getId(), is("root")); rootChildren = mRoot.getChildren(); assertThat(rootChildren, notNullValue()); assertThat(rootChildren.size(), is(2)); mChild1 = rootChildren.get(0); mChild2 = rootChildren.get(1); assertThat(mChild1.getId(), is("child1")); assertThat(mChild2.getId(), is("child2")); child1Children = mChild1.getChildren(); assertThat(child1Children, notNullValue()); assertThat(child1Children.size(), is(2)); mChild3 = child1Children.get(0); mChild4 = child1Children.get(1); assertThat(mChild3.getId(), is("child3")); assertThat(mChild4.getId(), is("child4")); }
@Test public void testIfEngineeringObjectInformationIsDeleted_shouldDeleteEOInformation() throws Exception { EDBObject object = new EDBObject("test"); object.putEDBObjectEntry(EDBConstants.MODEL_TYPE, EngineeringObjectModel.class.getName()); object.putEDBObjectEntry(EDBConstants.MODEL_OID, "test"); object.putEDBObjectEntry(EDBConstants.MODEL_VERSION, Integer.valueOf(1)); String key1 = getReferenceString(EngineeringObjectModel.class, "modelAId"); String key2 = getReferenceString(EngineeringObjectModel.class, "modelBId"); object.putEDBObjectEntry(key1, "testReferenceA"); object.putEDBObjectEntry(key2, "testReferenceB"); converter.convertEDBObjectToModel(EngineeringObjectModel.class, object); assertThat(object.get(key1), nullValue()); assertThat(object.get(key2), nullValue()); }