Search in sources :

Example 1 with XmiCodec

use of org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec in project emfcloud-modelserver by eclipse-emfcloud.

the class DefaultModelControllerTest method getAllXmiFormat.

@Test
public void getAllXmiFormat() throws EncodingException, IOException {
    final AtomicReference<JsonNode> response = new AtomicReference<>();
    final EClass brewingUnit = EcoreFactory.eINSTANCE.createEClass();
    Answer<Void> answer = invocation -> {
        response.set(invocation.getArgument(0));
        return null;
    };
    doAnswer(answer).when(context).json(any(JsonNode.class));
    final LinkedHashMap<String, List<String>> queryParams = new LinkedHashMap<>();
    queryParams.put(ModelServerPathParametersV1.FORMAT, Collections.singletonList(ModelServerPathParametersV1.FORMAT_XMI));
    when(context.queryParamMap()).thenReturn(queryParams);
    final Map<URI, EObject> allModels = Collections.singletonMap(URI.createURI("test"), brewingUnit);
    when(modelRepository.getAllModels()).thenReturn(allModels);
    modelController.getAll(context);
    assertThat(response.get().get(JsonResponseMember.DATA), is(equalTo(Json.object(Json.prop("test", new XmiCodec().encode(brewingUnit))))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) HttpURLConnection(java.net.HttpURLConnection) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CCommandExecutionResult(org.eclipse.emfcloud.modelserver.command.CCommandExecutionResult) PatchCommandHandler(org.eclipse.emfcloud.modelserver.emf.patch.PatchCommandHandler) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) Context(io.javalin.http.Context) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) JsonPatchHelper(org.eclipse.emfcloud.modelserver.emf.util.JsonPatchHelper) JsonNode(com.fasterxml.jackson.databind.JsonNode) Json(org.eclipse.emfcloud.modelserver.jsonschema.Json) CCommandFactory(org.eclipse.emfcloud.modelserver.command.CCommandFactory) ServerConfiguration(org.eclipse.emfcloud.modelserver.emf.configuration.ServerConfiguration) JsonResource(org.eclipse.emfcloud.jackson.resource.JsonResource) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) List(java.util.List) EcoreResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) DecodingException(org.eclipse.emfcloud.modelserver.common.codecs.DecodingException) EMFCommandType(org.eclipse.emfcloud.modelserver.edit.EMFCommandType) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) URI(org.eclipse.emf.common.util.URI) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) EMFModule(org.eclipse.emfcloud.jackson.module.EMFModule) CommandExecutionType(org.eclipse.emfcloud.modelserver.edit.CommandExecutionType) CodecsManager(org.eclipse.emfcloud.modelserver.emf.common.codecs.CodecsManager) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) CustomTypeSafeMatcher(org.hamcrest.CustomTypeSafeMatcher) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) CCommand(org.eclipse.emfcloud.modelserver.command.CCommand) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LinkedHashMap(java.util.LinkedHashMap) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher) Json.prop(org.eclipse.emfcloud.modelserver.jsonschema.Json.prop) Answer(org.mockito.stubbing.Answer) EAttribute(org.eclipse.emf.ecore.EAttribute) EClass(org.eclipse.emf.ecore.EClass) Suppliers(com.google.common.base.Suppliers) EMFMatchers.eEqualTo(org.eclipse.emfcloud.modelserver.tests.util.EMFMatchers.eEqualTo) EncodingException(org.eclipse.emfcloud.modelserver.common.codecs.EncodingException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) XmiCodec(org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Description(org.hamcrest.Description) MockitoHamcrest.intThat(org.mockito.hamcrest.MockitoHamcrest.intThat) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) DICodecsManager(org.eclipse.emfcloud.modelserver.emf.common.codecs.DICodecsManager) ModelServerPathParametersV2(org.eclipse.emfcloud.modelserver.common.ModelServerPathParametersV2) FeatureMatcher(org.hamcrest.FeatureMatcher) ModelServerPathParametersV1(org.eclipse.emfcloud.modelserver.common.ModelServerPathParametersV1) Matcher(org.hamcrest.Matcher) OSUtil.osLineSeparator(org.eclipse.emfcloud.modelserver.tests.util.OSUtil.osLineSeparator) Collections(java.util.Collections) JsonCodec(org.eclipse.emfcloud.modelserver.emf.common.codecs.JsonCodec) JsonNode(com.fasterxml.jackson.databind.JsonNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(org.eclipse.emf.common.util.URI) LinkedHashMap(java.util.LinkedHashMap) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) XmiCodec(org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec) Test(org.junit.Test)

Example 2 with XmiCodec

use of org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec in project emfcloud-modelserver by eclipse-emfcloud.

the class ModelServerClientV2Test method getElementByNameXMI.

@Test
@SuppressWarnings({ "checkstyle:ThrowsCount" })
public void getElementByNameXMI() throws ExecutionException, InterruptedException, EncodingException, MalformedURLException {
    final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    String getElementByNameXMIUrl = baseHttpUrlBuilder.addPathSegment(ModelServerPathsV2.MODEL_ELEMENT).addQueryParameter(ModelServerPathParametersV2.MODEL_URI, "SuperBrewer3000.json").addQueryParameter(ModelServerPathParametersV2.ELEMENT_NAME, "Simple Workflow").addQueryParameter(ModelServerPathParametersV2.FORMAT, ModelServerPathParametersV2.FORMAT_XMI).build().toString();
    interceptor.addRule().get().url(getElementByNameXMIUrl).respond(JsonResponse.success(new XmiCodec().encode(eClass)).toString());
    ModelServerClientV2 client = createClient();
    final CompletableFuture<Response<EObject>> f = client.getModelElementByName("SuperBrewer3000.json", "Simple Workflow", ModelServerPathParametersV2.FORMAT_XMI);
    assertTrue(EcoreUtil.equals(f.get().body(), eClass));
}
Also used : JsonResponse(org.eclipse.emfcloud.modelserver.emf.common.JsonResponse) Response(org.eclipse.emfcloud.modelserver.client.Response) EClass(org.eclipse.emf.ecore.EClass) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) XmiCodec(org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec) Test(org.junit.Test)

Example 3 with XmiCodec

use of org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec in project emfcloud-modelserver by eclipse-emfcloud.

the class ModelServerClientV2Test method getElementByIdXMI.

@Test
@SuppressWarnings({ "checkstyle:ThrowsCount" })
public void getElementByIdXMI() throws ExecutionException, InterruptedException, EncodingException, MalformedURLException {
    final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    String getElementByIdXMIUrl = baseHttpUrlBuilder.addPathSegment(ModelServerPathsV2.MODEL_ELEMENT).addQueryParameter(ModelServerPathParametersV2.MODEL_URI, "SuperBrewer3000.json").addQueryParameter(ModelServerPathParametersV2.ELEMENT_ID, "//@workflows.0").addQueryParameter(ModelServerPathParametersV2.FORMAT, ModelServerPathParametersV2.FORMAT_XMI).build().toString();
    interceptor.addRule().get().url(getElementByIdXMIUrl).respond(JsonResponse.success(new XmiCodec().encode(eClass)).toString());
    ModelServerClientV2 client = createClient();
    final CompletableFuture<Response<EObject>> f = client.getModelElementById("SuperBrewer3000.json", "//@workflows.0", ModelServerPathParametersV2.FORMAT_XMI);
    assertTrue(EcoreUtil.equals(f.get().body(), eClass));
}
Also used : JsonResponse(org.eclipse.emfcloud.modelserver.emf.common.JsonResponse) Response(org.eclipse.emfcloud.modelserver.client.Response) EClass(org.eclipse.emf.ecore.EClass) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) XmiCodec(org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec) Test(org.junit.Test)

Example 4 with XmiCodec

use of org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec in project emfcloud-modelserver by eclipse-emfcloud.

the class ModelServerClientTest method getXmi.

@Test
@SuppressWarnings({ "checkstyle:ThrowsCount" })
public void getXmi() throws ExecutionException, InterruptedException, EncodingException, MalformedURLException {
    final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    String getXmiUrl = baseHttpUrlBuilder.addPathSegment(ModelServerPathsV2.MODEL_BASE_PATH).addQueryParameter(ModelServerPathParametersV2.MODEL_URI, "SuperBrewer3000.json").addQueryParameter(ModelServerPathParametersV2.FORMAT, ModelServerPathParametersV2.FORMAT_XMI).build().toString();
    interceptor.addRule().get().url(getXmiUrl).respond(JsonResponse.success(new XmiCodec().encode(eClass)).toString());
    ModelServerClient client = createClient();
    final CompletableFuture<Response<EObject>> f = client.get("SuperBrewer3000.json", ModelServerPathParametersV2.FORMAT_XMI);
    assertTrue(EcoreUtil.equals(f.get().body(), eClass));
}
Also used : JsonResponse(org.eclipse.emfcloud.modelserver.emf.common.JsonResponse) EClass(org.eclipse.emf.ecore.EClass) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) XmiCodec(org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec) Test(org.junit.Test)

Example 5 with XmiCodec

use of org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec in project emfcloud-modelserver by eclipse-emfcloud.

the class ModelServerClientTest method getElementByNameXMI.

@Test
@SuppressWarnings({ "checkstyle:ThrowsCount" })
public void getElementByNameXMI() throws ExecutionException, InterruptedException, EncodingException, MalformedURLException {
    final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    String getElementByNameXMIUrl = baseHttpUrlBuilder.addPathSegment(ModelServerPathsV2.MODEL_ELEMENT).addQueryParameter(ModelServerPathParametersV2.MODEL_URI, "SuperBrewer3000.json").addQueryParameter(ModelServerPathParametersV2.ELEMENT_NAME, "Simple Workflow").addQueryParameter(ModelServerPathParametersV2.FORMAT, ModelServerPathParametersV2.FORMAT_XMI).build().toString();
    interceptor.addRule().get().url(getElementByNameXMIUrl).respond(JsonResponse.success(new XmiCodec().encode(eClass)).toString());
    ModelServerClient client = createClient();
    final CompletableFuture<Response<EObject>> f = client.getModelElementByName("SuperBrewer3000.json", "Simple Workflow", ModelServerPathParametersV2.FORMAT_XMI);
    assertTrue(EcoreUtil.equals(f.get().body(), eClass));
}
Also used : JsonResponse(org.eclipse.emfcloud.modelserver.emf.common.JsonResponse) EClass(org.eclipse.emf.ecore.EClass) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) XmiCodec(org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec) Test(org.junit.Test)

Aggregations

XmiCodec (org.eclipse.emfcloud.modelserver.common.codecs.XmiCodec)20 EClass (org.eclipse.emf.ecore.EClass)18 Test (org.junit.Test)18 JsonResponse (org.eclipse.emfcloud.modelserver.emf.common.JsonResponse)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 Response (org.eclipse.emfcloud.modelserver.client.Response)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 URI (org.eclipse.emf.common.util.URI)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 EcoreResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl)3 JsonResource (org.eclipse.emfcloud.jackson.resource.JsonResource)3 Suppliers (com.google.common.base.Suppliers)2 Context (io.javalin.http.Context)2 File (java.io.File)2