Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DeleteSubmodelElement Tests #191

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,20 @@ public void createSubmodelElement() {

}

@Test(expected = ElementDoesNotExistException.class)
@Test
public void deleteSubmodeleElement() {
SubmodelRepository repo = getSubmodelRepositoryWithDummySubmodels();
repo.deleteSubmodelElement(DummySubmodelFactory.SUBMODEL_SIMPLE_DATA_ID, "test123");
repo.deleteSubmodelElement(DummySubmodelFactory.SUBMODEL_SIMPLE_DATA_ID, DummySubmodelFactory.SUBMODEL_ELEMENT_SIMPLE_DATA_ID_SHORT);

try {
repo.getSubmodelElement(DummySubmodelFactory.SUBMODEL_SIMPLE_DATA_ID, "test123");
repo.getSubmodelElement(DummySubmodelFactory.SUBMODEL_SIMPLE_DATA_ID, DummySubmodelFactory.SUBMODEL_ELEMENT_SIMPLE_DATA_ID_SHORT);
fail();
} catch (ElementDoesNotExistException expected) {
}
}

@Test
public void createNestedSubmodelELement() {
public void createNestedSubmodelElement() {
SubmodelRepository repo = getSubmodelRepositoryWithDummySubmodels();
Property propertyInCollection = new DefaultProperty.Builder().idShort("test654").category("cat1").value("305").valueType(DataTypeDefXsd.INTEGER).build();
Property propertyInList = new DefaultProperty.Builder().idShort("test987").category("cat1").value("305").valueType(DataTypeDefXsd.INTEGER).build();
Expand All @@ -439,33 +439,33 @@ public void createNestedSubmodelELement() {
assertEquals("test987", propertyInSmeListCreated.getIdShort());
}

@Test(expected = ElementDoesNotExistException.class)
@Test
public void deleteNestedSubmodelElementInSubmodelElementCollection() {
SubmodelRepository repo = getSubmodelRepositoryWithDummySubmodels();
SubmodelRepository repo = getSubmodelRepositoryWithHierarchicalSubmodelElements();

String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + DummySubmodelFactory.SUBMODEL_ELEMENT_SECOND_ID_SHORT;
String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + "." + DummySubmodelFactory.SUBMODEL_ELEMENT_SECOND_ID_SHORT;

repo.deleteSubmodelElement(DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ID, idShortPathPropertyInSmeCol);

try {
repo.getSubmodelElement(DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ID, idShortPathPropertyInSmeCol);
fail();
} catch (ElementDoesNotExistException expected) {
throw expected;

}
}

@Test(expected = ElementDoesNotExistException.class)
@Test
public void deleteNestedSubmodelElementInSubmodelElementList() {
SubmodelRepository repo = getSubmodelRepositoryWithDummySubmodels();
SubmodelRepository repo = getSubmodelRepositoryWithHierarchicalSubmodelElements();

repo.deleteSubmodelElement(DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ID, generateIdShortPath());

try {
repo.getSubmodelElement(DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ID, generateIdShortPath());
fail();
} catch (ElementDoesNotExistException expected) {
throw expected;

}
}

Expand Down Expand Up @@ -532,6 +532,12 @@ private SubmodelRepository getSubmodelRepositoryWithDummySubmodels() {
return repo;
}

private SubmodelRepository getSubmodelRepositoryWithHierarchicalSubmodelElements() {
Collection<Submodel> expectedSubmodels = Arrays.asList(DummySubmodelFactory.createOperationalDataSubmodelWithHierarchicalSubmodelElements());
SubmodelRepository repo = getSubmodelRepository(expectedSubmodels);
return repo;
}

private void assertIsEmpty(Collection<Submodel> submodels) {
assertTrue(submodels.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ public void createSubmodelElement() {
assertEquals("test123", submodelEl.getIdShort());
}

@Test(expected = ElementDoesNotExistException.class)
@Test
public void deleteSubmodelElement() {
Submodel technicalData = DummySubmodelFactory.createTechnicalDataSubmodel();
SubmodelService submodelService = getSubmodelService(technicalData);
submodelService.deleteSubmodelElement("test123");
submodelService.deleteSubmodelElement(SubmodelServiceHelper.SUBMODEL_TECHNICAL_DATA_PROPERTY_ID_SHORT);

try {
submodelService.getSubmodelElement("test123");
Expand Down Expand Up @@ -346,24 +346,23 @@ public void createNestedSubmodelElement() {
assertEquals("test456", propertyInSmeListCreated.getIdShort());
}

@Test(expected = ElementDoesNotExistException.class)
@Test
public void deleteNestedSubmodelElementInSubmodelElementCollection() {
Submodel operationDataSubmodel = DummySubmodelFactory.createOperationalDataSubmodelWithHierarchicalSubmodelElements();
SubmodelService submodelService = getSubmodelService(operationDataSubmodel);

String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + DummySubmodelFactory.SUBMODEL_ELEMENT_SECOND_ID_SHORT;
String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + "." + DummySubmodelFactory.SUBMODEL_ELEMENT_SECOND_ID_SHORT;

submodelService.deleteSubmodelElement(idShortPathPropertyInSmeCol);

try {
submodelService.getSubmodelElement(idShortPathPropertyInSmeCol);
fail();
} catch (ElementDoesNotExistException expected) {
throw expected;
}
}

@Test(expected = ElementDoesNotExistException.class)
@Test
public void deleteNestedSubmodelElementInSubmodelElementList() {
Submodel operationDataSubmodel = DummySubmodelFactory.createOperationalDataSubmodelWithHierarchicalSubmodelElements();
SubmodelService submodelService = getSubmodelService(operationDataSubmodel);
Expand All @@ -374,7 +373,6 @@ public void deleteNestedSubmodelElementInSubmodelElementList() {
submodelService.getSubmodelElement(generateIdShortPath());
fail();
} catch (ElementDoesNotExistException expected) {
throw expected;
}
}

Expand Down
Loading