@Test public void testGetVersionedRulesFromPackage() throws IOException { String mockString = "mockString"; GuvnorServiceImpl sut = new GuvnorServiceImpl(GUNVOR_REST_URL, USERNAME, PASSWORD); GuvnorServiceImpl spy = spy(sut); HttpURLConnection mockConnection = mock(HttpURLConnection.class); when(spy.openConnection(GUNVOR_REST_URL)).thenReturn(mockConnection); InputStream mockInputStream = new ByteArrayInputStream(mockString.getBytes("UTF-8")); when(mockConnection.getInputStream()).thenReturn(mockInputStream); String response = spy.getVersionedRulesFromPackage(); verify(mockConnection, times(1)).setRequestMethod("GET"); verify(mockConnection, times(1)).connect(); verify(mockConnection, times(1)).getInputStream(); assertNotNull(response); assertNotEquals(mockString, response); }
@Override public String getVersionedRulesFromPackage() throws IOException { String source = null; final HttpURLConnection connection = openConnection(this.endpointAddress); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", MediaType.TEXT_PLAIN); final StringBuilder passwordStringBuilder = new StringBuilder(); passwordStringBuilder.append(guvnorServiceUsername); passwordStringBuilder.append(":"); passwordStringBuilder.append(guvnorServicePassword); final String passwordString = passwordStringBuilder.toString(); final StringBuilder propertyStringBuilder = new StringBuilder(); propertyStringBuilder.append("Basic "); propertyStringBuilder.append(new Base64().encodeToString(passwordString .getBytes())); connection.setRequestProperty("Authorization", propertyStringBuilder.toString()); connection.connect(); source = readAsString(connection.getInputStream()); logger.debug("DRL source: " + source); return source; }
GuvnorServiceImpl implements GuvnorService { @Override public String getVersionedRulesFromPackage() throws IOException { String source = null; final HttpURLConnection connection = openConnection(this.endpointAddress); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", MediaType.TEXT_PLAIN); final StringBuilder passwordStringBuilder = new StringBuilder(); passwordStringBuilder.append(guvnorServiceUsername); passwordStringBuilder.append(":"); passwordStringBuilder.append(guvnorServicePassword); final String passwordString = passwordStringBuilder.toString(); final StringBuilder propertyStringBuilder = new StringBuilder(); propertyStringBuilder.append("Basic "); propertyStringBuilder.append(new Base64().encodeToString(passwordString .getBytes())); connection.setRequestProperty("Authorization", propertyStringBuilder.toString()); connection.connect(); source = readAsString(connection.getInputStream()); logger.debug("DRL source: " + source); return source; } }
GuvnorServiceImpl implements GuvnorService { @Override public String getVersionedRulesFromPackage() throws IOException { String source = null; final HttpURLConnection connection = openConnection(this.endpointAddress); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", MediaType.TEXT_PLAIN); final StringBuilder passwordStringBuilder = new StringBuilder(); passwordStringBuilder.append(guvnorServiceUsername); passwordStringBuilder.append(":"); passwordStringBuilder.append(guvnorServicePassword); final String passwordString = passwordStringBuilder.toString(); final StringBuilder propertyStringBuilder = new StringBuilder(); propertyStringBuilder.append("Basic "); propertyStringBuilder.append(new Base64().encodeToString(passwordString .getBytes())); connection.setRequestProperty("Authorization", propertyStringBuilder.toString()); connection.connect(); source = readAsString(connection.getInputStream()); logger.debug("DRL source: " + source); return source; } GuvnorServiceImpl(String endpointAddress,
			String guvnorServiceUsername, String guvnorServicePassword); }
GuvnorServiceImpl implements GuvnorService { @Override public String getVersionedRulesFromPackage() throws IOException { String source = null; final HttpURLConnection connection = openConnection(this.endpointAddress); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", MediaType.TEXT_PLAIN); final StringBuilder passwordStringBuilder = new StringBuilder(); passwordStringBuilder.append(guvnorServiceUsername); passwordStringBuilder.append(":"); passwordStringBuilder.append(guvnorServicePassword); final String passwordString = passwordStringBuilder.toString(); final StringBuilder propertyStringBuilder = new StringBuilder(); propertyStringBuilder.append("Basic "); propertyStringBuilder.append(new Base64().encodeToString(passwordString .getBytes())); connection.setRequestProperty("Authorization", propertyStringBuilder.toString()); connection.connect(); source = readAsString(connection.getInputStream()); logger.debug("DRL source: " + source); return source; } GuvnorServiceImpl(String endpointAddress,
			String guvnorServiceUsername, String guvnorServicePassword); @Override String getVersionedRulesFromPackage(); }
GuvnorServiceImpl implements GuvnorService { @Override public String getVersionedRulesFromPackage() throws IOException { String source = null; final HttpURLConnection connection = openConnection(this.endpointAddress); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", MediaType.TEXT_PLAIN); final StringBuilder passwordStringBuilder = new StringBuilder(); passwordStringBuilder.append(guvnorServiceUsername); passwordStringBuilder.append(":"); passwordStringBuilder.append(guvnorServicePassword); final String passwordString = passwordStringBuilder.toString(); final StringBuilder propertyStringBuilder = new StringBuilder(); propertyStringBuilder.append("Basic "); propertyStringBuilder.append(new Base64().encodeToString(passwordString .getBytes())); connection.setRequestProperty("Authorization", propertyStringBuilder.toString()); connection.connect(); source = readAsString(connection.getInputStream()); logger.debug("DRL source: " + source); return source; } GuvnorServiceImpl(String endpointAddress,
			String guvnorServiceUsername, String guvnorServicePassword); @Override String getVersionedRulesFromPackage();  }