@Test public void getOneXmiFormat() throws EncodingException { final AtomicReference<JsonNode> response = new AtomicReference<>(); final BrewingUnit brewingUnit = CoffeeFactory.eINSTANCE.createBrewingUnit(); 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("format", Collections.singletonList("xmi")); when(context.queryParamMap()).thenReturn(queryParams); when(modelRepository.getModel("test")).thenReturn(Optional.of(brewingUnit)); modelController.getOne(context, "test"); assertThat(response.get().get("data"), is(equalTo(new XmiCodec().encode(brewingUnit)))); }
public void getOne(final Context ctx, final String modeluri) { this.modelRepository.getModel(modeluri).ifPresentOrElse( model -> { if (model == null) { ctx.json(JsonResponse.error("")); } else { try { ctx.json(JsonResponse.success(codecs.encode(ctx, model))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } } }, () -> handleError(ctx, 404, "Model '" + modeluri + "' not found!")); }
ModelController { public void getOne(final Context ctx, final String modeluri) { this.modelRepository.getModel(modeluri).ifPresentOrElse( model -> { if (model == null) { ctx.json(JsonResponse.error("")); } else { try { ctx.json(JsonResponse.success(codecs.encode(ctx, model))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } } }, () -> handleError(ctx, 404, "Model '" + modeluri + "' not found!")); } }
ModelController { public void getOne(final Context ctx, final String modeluri) { this.modelRepository.getModel(modeluri).ifPresentOrElse( model -> { if (model == null) { ctx.json(JsonResponse.error("")); } else { try { ctx.json(JsonResponse.success(codecs.encode(ctx, model))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } } }, () -> handleError(ctx, 404, "Model '" + modeluri + "' not found!")); } @Inject  ModelController(final ModelRepository modelRepository, final SessionController sessionController,
      final ServerConfiguration serverConfiguration); }
ModelController { public void getOne(final Context ctx, final String modeluri) { this.modelRepository.getModel(modeluri).ifPresentOrElse( model -> { if (model == null) { ctx.json(JsonResponse.error("")); } else { try { ctx.json(JsonResponse.success(codecs.encode(ctx, model))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } } }, () -> handleError(ctx, 404, "Model '" + modeluri + "' not found!")); } @Inject  ModelController(final ModelRepository modelRepository, final SessionController sessionController,
      final ServerConfiguration serverConfiguration); void create(final Context ctx, final String modeluri); void delete(final Context ctx, final String modeluri); void getAll(final Context ctx); void getOne(final Context ctx, final String modeluri); void update(final Context ctx, final String modeluri); void save(final Context ctx, final String modeluri); Handler getModelUrisHandler(); void executeCommand(final Context ctx, final String modelURI); }
ModelController { public void getOne(final Context ctx, final String modeluri) { this.modelRepository.getModel(modeluri).ifPresentOrElse( model -> { if (model == null) { ctx.json(JsonResponse.error("")); } else { try { ctx.json(JsonResponse.success(codecs.encode(ctx, model))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } } }, () -> handleError(ctx, 404, "Model '" + modeluri + "' not found!")); } @Inject  ModelController(final ModelRepository modelRepository, final SessionController sessionController,
      final ServerConfiguration serverConfiguration); void create(final Context ctx, final String modeluri); void delete(final Context ctx, final String modeluri); void getAll(final Context ctx); void getOne(final Context ctx, final String modeluri); void update(final Context ctx, final String modeluri); void save(final Context ctx, final String modeluri); Handler getModelUrisHandler(); void executeCommand(final Context ctx, final String modelURI);  }