GetSchemaHandler implements OutputOperationHandler<GetSchema, Schema> { @Override public Schema doOperation(final GetSchema operation, final Context context, final Store store) throws OperationException { final Schema schema; if (null == operation) { throw new OperationException("Operation cannot be null"); } if (operation.isCompact()) { schema = Schema.fromJson(store.getSchema().toCompactJson()); } else { schema = store.getOriginalSchema(); } return schema; }  @Override Schema doOperation(final GetSchema operation, final Context context, final Store store);  }
@Test public void shouldReturnCompactSchema() throws OperationException { given(store.getProperties()).willReturn(properties); given(store.getSchema()).willReturn(schema); given(context.getUser()).willReturn(user); final GetSchema operation = new GetSchema.Builder() .compact(true) .build(); final Schema result = handler.doOperation(operation, context, store); assertNotNull(result); JsonAssert.assertNotEqual(schema.toJson(true), result.toJson(true)); JsonAssert.assertEquals(compactSchemaBytes, result.toJson(true)); }
@Test public void shouldReturnFullSchema() throws OperationException { given(store.getProperties()).willReturn(properties); given(store.getOriginalSchema()).willReturn(schema); given(context.getUser()).willReturn(user); final GetSchema operation = new GetSchema(); final Schema result = handler.doOperation(operation, context, store); assertNotNull(result); JsonAssert.assertEquals(schema.toJson(true), result.toJson(true)); }
@Test public void shouldThrowExceptionForNullOperation() throws OperationException { final GetSchema operation = null; try { handler.doOperation(operation, context, store); } catch (final OperationException e) { assertTrue(e.getMessage().contains("Operation cannot be null")); } }