### Question:
MetadataClientRequestProcessor extends MessageProcessorBase { @Override public void process() throws Exception { switch (target) { case LIST_CLIENTS: handleListClients(); return; case LIST_CENTRAL_SERVICES: handleListCentralServices(); return; default: break; } } MetadataClientRequestProcessor(String target,
            HttpServletRequest request, HttpServletResponse response); boolean canProcess(); @Override void process(); @Override MessageInfo createRequestMessageInfo();  }### Answer:
@Test public void shouldProcessListClients() throws Exception { final List<MemberInfo> expectedMembers = Arrays.asList( createMember("producer", null), createMember("producer", "subsystem"), createMember("anothermemeber", null), createMember("anothermemeber", "somesub"), createMember("thirdmember", null)); GlobalConf.reload(new TestSuiteGlobalConf() { @Override public List<MemberInfo> getMembers(String... instanceIdentifier) { String[] instances = instanceIdentifier; assertThat("Wrong Xroad instance in query", instances, arrayContaining(EXPECTED_XR_INSTANCE)); return expectedMembers; } }); MetadataClientRequestProcessor processorToTest = new MetadataClientRequestProcessor(LIST_CLIENTS, mockRequest, mockResponse); processorToTest.process(); assertContentTypeIsIn(xmlUtf8ContentTypes()); List<MemberInfo> members = unmarshaller.unmarshal( mockServletOutputStream.getResponseSource(), ClientListType.class) .getValue() .getMember() .stream() .map(clientType -> new MemberInfo(clientType.getId(), clientType.getName())) .collect(Collectors.toList()); assertThat("Wrong amount of clients", members.size(), is(expectedMembers.size())); assertThat("Wrong members", members, containsInAnyOrder(expectedMembers.toArray())); }
@Test public void shouldProcessListClientsAndReturnJson() throws Exception { final List<MemberInfo> expectedMembers = Arrays.asList( createMember("producer", null), createMember("producer", "subsystem")); GlobalConf.reload(new TestSuiteGlobalConf() { @Override public List<MemberInfo> getMembers(String... instanceIdentifier) { String[] instances = instanceIdentifier; assertThat("Wrong Xroad instance in query", instances, arrayContaining(EXPECTED_XR_INSTANCE)); return expectedMembers; } }); MetadataClientRequestProcessor processorToTest = new MetadataClientRequestProcessor(LIST_CLIENTS, mockJsonRequest, mockResponse); processorToTest.process(); assertContentTypeIsIn(Arrays.asList("application/json; charset=utf-8")); }
@Test public void shouldProcessListCentralServices() throws Exception { final List<CentralServiceId> expectedCentraServices = Arrays.asList( create(EXPECTED_XR_INSTANCE, "getInfo"), create(EXPECTED_XR_INSTANCE, "someService"), create(EXPECTED_XR_INSTANCE, "getRandom")); GlobalConf.reload(new TestSuiteGlobalConf() { @Override public List<CentralServiceId> getCentralServices(String instanceIdentifier) { assertThat("Wrong Xroad instance in query", instanceIdentifier, is(EXPECTED_XR_INSTANCE)); return expectedCentraServices; } }); MetadataClientRequestProcessor processorToTest = new MetadataClientRequestProcessor(LIST_CENTRAL_SERVICES, mockRequest, mockResponse); processorToTest.process(); assertContentTypeIsIn(xmlUtf8ContentTypes()); List<CentralServiceId> resultCentralServices = unmarshaller.unmarshal( mockServletOutputStream.getResponseSource(), CentralServiceListType.class) .getValue().getCentralService(); assertThat("Wrong amount of services", resultCentralServices.size(), is(expectedCentraServices.size())); assertThat("Wrong services", resultCentralServices, containsInAnyOrder(expectedCentraServices.toArray())); }