// Find the request we need private RestItem getRestItems(ServiceRequest request, String name) { RestItem matchingRest = null; Iterator<RestItem> itemRestIterator = request.getServiceRestItems().iterator(); do { matchingRest = itemRestIterator.next(); if (matchingRest.getName().compareTo(name) != 0) { matchingRest = null; } } while (itemRestIterator.hasNext() && (matchingRest == null)); return matchingRest; }
@Before public void setUp() throws Exception { HttpServices.setHttpServices(mock(HttpServices.class)); EchoSender.terminate(); MQListener.terminate(); WorkQueueMonitor.terminate(); if (svcThreadRunning == false) { ServiceThreadExecutor.createExecutor(); svcThreadRunning = true; } /* * CtagResourceMap.reset(); EchoResourceMap.reset(); * ResourceWorkerMap.reset(); ResourceWorkQueue.reset(); * WorkQueue.reset(); */ ResourceWorkerMap.initWorkerMap(); SystemProperties.setProperty("ss.echo_sender_interval", "20"); SystemProperties.setProperty("ss.echo_max_missed_echos", "3"); connFactory = new ConnectionFactory(); connFactory.setHost("127.0.0.1"); connFactory.setVirtualHost("/fern"); connFactory.setUsername("sportingsolutions@fern"); connFactory.setPassword("sporting"); connection = connFactory.newConnection(); channel = connection.createChannel(); // Prepare test data to create the Resource requestItems = JsonHelper.toRestItems(resources); requestSR = new ServiceRequest(); // requestSR.setAuthToken("AUTH_TOKEN_01"); requestSR.setServiceRestItems(requestItems); restItem = getRestItems(requestSR, "Fern v NotFern"); String responseAMQEndPoint = "[{\"Name\":\"stream\",\"Links\":[{\"Relation\":\"amqp\",\"Href\":\"amqp://sportingsolutions%40fern:[email protected]:5672/fern/" + intTestQueue + "\"}]}]"; responseItems = JsonHelper.toRestItems(responseAMQEndPoint); // responseSR.setAuthToken("AUTH_TOKEN_01"); responseSR.setServiceRestItems(responseItems); // Here we mock http services. It still's try to connect but we have a // response ready for the call doAnswer( new Answer<ServiceRequest>() { public ServiceRequest answer(InvocationOnMock invocation) throws Throwable { return responseSR; } }) .when(HttpServices.getHttpService()) .processRequest( "http://api.sportingsolutions.com/rels/stream/amqp", restItem, "Fern v NotFern"); connectedEventCalled = false; disconnectedEventCalled = false; streamEventCalled = false; }