-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task #1174 Update tests on error response
- Loading branch information
1 parent
2c050ad
commit 7113092
Showing
3 changed files
with
247 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
306 changes: 153 additions & 153 deletions
306
...est/src/de/dlr/sc/virsat/server/resources/modelaccess/CategoryAssignmentResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,153 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 German Aerospace Center (DLR), Simulation and Software Technology, Germany. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package de.dlr.sc.virsat.server.resources.modelaccess; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.StringWriter; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.jetty.http.HttpStatus; | ||
import org.junit.Test; | ||
|
||
import de.dlr.sc.virsat.model.dvlm.json.JAXBUtility; | ||
import de.dlr.sc.virsat.model.extension.tests.model.TestCategoryAllProperty; | ||
import de.dlr.sc.virsat.model.extension.tests.model.TestCategoryCompositionArray; | ||
import de.dlr.sc.virsat.server.resources.AModelAccessResourceTest; | ||
import de.dlr.sc.virsat.server.resources.ModelAccessResource; | ||
import de.dlr.sc.virsat.server.test.VersionControlTestHelper; | ||
|
||
public class CategoryAssignmentResourceTest extends AModelAccessResourceTest { | ||
|
||
@Test | ||
public void testCaAllPropertyGet() throws Exception { | ||
testGetCa(tcAllProperty); | ||
} | ||
|
||
@Test | ||
public void testCaBeanAGet() throws Exception { | ||
testGetCa(tcBeanA); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionGet() throws Exception { | ||
testGetCa(tcComposition); | ||
} | ||
|
||
@Test | ||
public void testCaRefernceGet() throws Exception { | ||
testGetCa(tcReference); | ||
} | ||
|
||
@Test | ||
public void testCaIntrinsicArrayGet() throws Exception { | ||
testGetCa(tcIntrinsicArray); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionArrayGet() throws Exception { | ||
testGetCa(tcCompositionArray, new Class[] {tcCompositionArray.getClass(), tcAllProperty.getClass()}); | ||
} | ||
|
||
@Test | ||
public void testCaReferenceArrayGet() throws Exception { | ||
testGetCa(tcReferenceArray); | ||
} | ||
|
||
@Test | ||
public void testCaAllPropertyPut() throws Exception { | ||
testPutCa(tcAllProperty); | ||
} | ||
|
||
@Test | ||
public void testCaBeanAPut() throws Exception { | ||
testPutCa(tcBeanA); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionPut() throws Exception { | ||
testPutCa(tcComposition); | ||
} | ||
|
||
@Test | ||
public void testCaReferncePut() throws Exception { | ||
testPutCa(tcReference); | ||
} | ||
|
||
@Test | ||
public void testCaIntrinsicArrayPut() throws Exception { | ||
testPutCa(tcIntrinsicArray); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionArrayPut() throws Exception { | ||
int commits = VersionControlTestHelper.countCommits(testServerRepository.getLocalRepositoryPath()); | ||
|
||
// Manually marshall the Class because Entity.entity doesn't marshall | ||
// the TestCategoryAllProperty right because of generics | ||
JAXBUtility jaxbUtility = new JAXBUtility(new Class[] {TestCategoryCompositionArray.class, TestCategoryAllProperty.class}); | ||
StringWriter sw = new StringWriter(); | ||
jaxbUtility.getJsonMarshaller().marshal(tcCompositionArray, sw); | ||
String jsonIn = sw.toString(); | ||
|
||
Response response = webTarget | ||
.path(ModelAccessResource.CA) | ||
.request() | ||
.header(HttpHeaders.AUTHORIZATION, USER_WITH_REPO_HEADER) | ||
.put(Entity.json(jsonIn)); | ||
assertEquals(HttpStatus.OK_200, response.getStatus()); | ||
|
||
assertEquals("One new commit because boolean was changed from null to false", commits + 1, | ||
VersionControlTestHelper.countCommits(testServerRepository.getLocalRepositoryPath())); | ||
} | ||
|
||
@Test | ||
public void testCaReferenceArrayPut() throws Exception { | ||
testPutCa(tcReferenceArray); | ||
} | ||
|
||
@Test | ||
public void testCaDelete() throws Exception { | ||
testDeleteCa(tcAllProperty); | ||
} | ||
|
||
@Test | ||
public void testCreateCa() throws Exception { | ||
String wantedTypeFqn = tcBeanA.getFullQualifiedCategoryName(); | ||
|
||
Response response = getTestRequestBuilderWithQueryParam(ModelAccessResource.CA + "/" + tSei.getUuid(), | ||
ModelAccessResource.QP_FULL_QUALIFIED_NAME, wantedTypeFqn).post(Entity.json(null)); | ||
|
||
assertIUuidGotCreated(response, wantedTypeFqn, ed, tSei.getStructuralElementInstance().getCategoryAssignments()); | ||
} | ||
|
||
@Test | ||
public void testErrorResponses() { | ||
assertNotFoundResponse(getTestRequestBuilder(ModelAccessResource.CA + "/unknown").get()); | ||
|
||
assertNotFoundResponse(getTestRequestBuilder(ModelAccessResource.CA + "/unknown").delete()); | ||
|
||
assertNotFoundResponse(getTestRequestBuilder(ModelAccessResource.CA + "/unknown").post(Entity.json(null))); | ||
|
||
// Assert check ca discipline via sei | ||
setDiscipline(tSei.getStructuralElementInstance(), anotherDiscipline); | ||
assertCommandNotExecuteableErrorResponse(getTestRequestBuilder(ModelAccessResource.CA + "/" + tcAllProperty.getUuid()).delete()); | ||
|
||
setDiscipline(tSei.getStructuralElementInstance(), anotherDiscipline); | ||
String wantedTypeFqn = tcBeanA.getFullQualifiedCategoryName(); | ||
|
||
Response response = getTestRequestBuilderWithQueryParam(ModelAccessResource.CA + "/" + tSei.getUuid(), | ||
ModelAccessResource.QP_FULL_QUALIFIED_NAME, wantedTypeFqn).post(Entity.json(null)); | ||
assertCommandNotExecuteableErrorResponse(response); | ||
} | ||
} | ||
/******************************************************************************* | ||
* Copyright (c) 2021 German Aerospace Center (DLR), Simulation and Software Technology, Germany. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package de.dlr.sc.virsat.server.resources.modelaccess; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.StringWriter; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.jetty.http.HttpStatus; | ||
import org.junit.Test; | ||
|
||
import de.dlr.sc.virsat.model.dvlm.json.JAXBUtility; | ||
import de.dlr.sc.virsat.model.extension.tests.model.TestCategoryAllProperty; | ||
import de.dlr.sc.virsat.model.extension.tests.model.TestCategoryCompositionArray; | ||
import de.dlr.sc.virsat.server.resources.AModelAccessResourceTest; | ||
import de.dlr.sc.virsat.server.resources.ModelAccessResource; | ||
import de.dlr.sc.virsat.server.test.VersionControlTestHelper; | ||
|
||
public class CategoryAssignmentResourceTest extends AModelAccessResourceTest { | ||
|
||
@Test | ||
public void testCaAllPropertyGet() throws Exception { | ||
testGetCa(tcAllProperty); | ||
} | ||
|
||
@Test | ||
public void testCaBeanAGet() throws Exception { | ||
testGetCa(tcBeanA); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionGet() throws Exception { | ||
testGetCa(tcComposition); | ||
} | ||
|
||
@Test | ||
public void testCaRefernceGet() throws Exception { | ||
testGetCa(tcReference); | ||
} | ||
|
||
@Test | ||
public void testCaIntrinsicArrayGet() throws Exception { | ||
testGetCa(tcIntrinsicArray); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionArrayGet() throws Exception { | ||
testGetCa(tcCompositionArray, new Class[] {tcCompositionArray.getClass(), tcAllProperty.getClass()}); | ||
} | ||
|
||
@Test | ||
public void testCaReferenceArrayGet() throws Exception { | ||
testGetCa(tcReferenceArray); | ||
} | ||
|
||
@Test | ||
public void testCaAllPropertyPut() throws Exception { | ||
testPutCa(tcAllProperty); | ||
} | ||
|
||
@Test | ||
public void testCaBeanAPut() throws Exception { | ||
testPutCa(tcBeanA); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionPut() throws Exception { | ||
testPutCa(tcComposition); | ||
} | ||
|
||
@Test | ||
public void testCaReferncePut() throws Exception { | ||
testPutCa(tcReference); | ||
} | ||
|
||
@Test | ||
public void testCaIntrinsicArrayPut() throws Exception { | ||
testPutCa(tcIntrinsicArray); | ||
} | ||
|
||
@Test | ||
public void testCaCompositionArrayPut() throws Exception { | ||
int commits = VersionControlTestHelper.countCommits(testServerRepository.getLocalRepositoryPath()); | ||
|
||
// Manually marshall the Class because Entity.entity doesn't marshall | ||
// the TestCategoryAllProperty right because of generics | ||
JAXBUtility jaxbUtility = new JAXBUtility(new Class[] {TestCategoryCompositionArray.class, TestCategoryAllProperty.class}); | ||
StringWriter sw = new StringWriter(); | ||
jaxbUtility.getJsonMarshaller().marshal(tcCompositionArray, sw); | ||
String jsonIn = sw.toString(); | ||
|
||
Response response = webTarget | ||
.path(ModelAccessResource.CA) | ||
.request() | ||
.header(HttpHeaders.AUTHORIZATION, USER_WITH_REPO_HEADER) | ||
.put(Entity.json(jsonIn)); | ||
assertEquals(HttpStatus.OK_200, response.getStatus()); | ||
|
||
assertEquals("One new commit because boolean was changed from null to false", commits + 1, | ||
VersionControlTestHelper.countCommits(testServerRepository.getLocalRepositoryPath())); | ||
} | ||
|
||
@Test | ||
public void testCaReferenceArrayPut() throws Exception { | ||
testPutCa(tcReferenceArray); | ||
} | ||
|
||
@Test | ||
public void testCaDelete() throws Exception { | ||
testDeleteCa(tcAllProperty); | ||
} | ||
|
||
@Test | ||
public void testCreateCa() throws Exception { | ||
String wantedTypeFqn = tcBeanA.getFullQualifiedCategoryName(); | ||
|
||
Response response = getTestRequestBuilderWithQueryParam(ModelAccessResource.CA + "/" + tSei.getUuid(), | ||
ModelAccessResource.QP_FULL_QUALIFIED_NAME, wantedTypeFqn).post(Entity.json(null)); | ||
|
||
assertIUuidGotCreated(response, wantedTypeFqn, ed, tSei.getStructuralElementInstance().getCategoryAssignments()); | ||
} | ||
|
||
@Test | ||
public void testErrorResponses() { | ||
assertNotFoundResponse(getTestRequestBuilder(ModelAccessResource.CA + "/unknown").get()); | ||
|
||
assertNotFoundResponse(getTestRequestBuilder(ModelAccessResource.CA + "/unknown").delete()); | ||
|
||
assertNotFoundResponse(getTestRequestBuilder(ModelAccessResource.CA + "/unknown").post(Entity.json(null))); | ||
|
||
// Assert check ca discipline via sei | ||
setDiscipline(tSei.getStructuralElementInstance(), anotherDiscipline); | ||
assertForbiddenResponse(getTestRequestBuilder(ModelAccessResource.CA + "/" + tcAllProperty.getUuid()).delete()); | ||
|
||
setDiscipline(tSei.getStructuralElementInstance(), anotherDiscipline); | ||
String wantedTypeFqn = tcBeanA.getFullQualifiedCategoryName(); | ||
|
||
Response response = getTestRequestBuilderWithQueryParam(ModelAccessResource.CA + "/" + tSei.getUuid(), | ||
ModelAccessResource.QP_FULL_QUALIFIED_NAME, wantedTypeFqn).post(Entity.json(null)); | ||
assertForbiddenResponse(response); | ||
} | ||
} |
Oops, something went wrong.