Skip to content

Commit

Permalink
Merge pull request #1175 from virtualsatellite/feature/1174-improve-d…
Browse files Browse the repository at this point in the history
…ata-access-of-virtual-satellite-headless

Improve data access via virtual satellite headless
  • Loading branch information
dellerDLR committed Jul 31, 2024
2 parents da48e94 + 176fbab commit 098b139
Show file tree
Hide file tree
Showing 14 changed files with 877 additions and 800 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TIP: Instead you can also use the Management API of the running Server.
|Start the Server executable with:
[subs=+quotes]
....
*"-configFile {path to server.properties}"*
*"-configFile {path to server.properties}" -port {port}*
....
The Server will start and try to load the repositories defined in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void initServerAndClient() throws Exception {
.sslContext(ctx)
.build();

URI uriHttp = UriBuilder.fromUri(HttpScheme.HTTP.asString() + "://localhost:" + VirSatJettyServer.VIRSAT_JETTY_PORT).build();
URI uriHttp = UriBuilder.fromUri(HttpScheme.HTTP.asString() + "://localhost:" + Activator.VIRSAT_JETTY_PORT).build();
httpTarget = httpClient.target(uriHttp).path("/status");

URI uriHttps = UriBuilder.fromUri(HttpScheme.HTTPS.asString() + "://localhost:" + VirSatJettyServer.VIRSAT_JETTY_PORT_HTTPS).build();
Expand Down

Large diffs are not rendered by default.

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);
}
}
Loading

0 comments on commit 098b139

Please sign in to comment.