/** * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#updated(java.lang.String, java.util.Dictionary)}. */ @Test() public void testUpdatedInsertsCredentialsOk() throws Exception { ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl(); UrlCredentials credentials = connFactory.getCredentials(TEST_URL); assert credentials == null : "Expected no credentials to be found!"; Dictionary<String, ?> props = createBasicAuthConfig(TEST_URL.toExternalForm()); connFactory.updated("pid1", props); credentials = connFactory.getCredentials(TEST_URL); assert credentials != null : "Expected valid credentials to be found!"; }
/** * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#getBasicAuthCredentials(UrlCredentials)}. */ @Test() public void testGetBasicAuthCredentialsOk() throws Exception { ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl(); Dictionary<String, ?> props = createBasicAuthConfig(TEST_URL.toExternalForm()); connFactory.updated("pid1", props); UrlCredentials credentials = connFactory.getCredentials(TEST_URL); assert credentials != null : "Expected valid credentials to be found!"; String header = new ConnectionFactoryImpl().getBasicAuthCredentials(credentials.getCredentials()); assert header != null : "Expected valid HTTP header to be returned!"; assert header.equals(header.trim()) : "Expected HTTP header not to contain any leading/trailing whitespace!"; assert "Basic Zm9vOmJhcg==".equals(header) : "Expected HTTP header to be constant!"; }
/** * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#deleted(java.lang.String)}. */ @Test() public void testDeleted() throws Exception { ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl(); Dictionary<String, ?> props = createBasicAuthConfig(TEST_URL.toExternalForm()); connFactory.updated("pid1", props); UrlCredentials credentials = connFactory.getCredentials(TEST_URL); assert credentials != null : "Expected valid credentials to be found!"; connFactory.deleted("pid1"); credentials = connFactory.getCredentials(TEST_URL); assert credentials == null : "Expected no credentials to be found!"; }
/** * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#updated(java.lang.String, java.util.Dictionary)}. */ @Test() public void testUpdatedUpdatesCredentialsOk() throws Exception { ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl(); Dictionary<String, Object> props = createBasicAuthConfig(TEST_URL.toExternalForm()); connFactory.updated("pid1", props); UrlCredentials credentials1 = connFactory.getCredentials(TEST_URL); assert credentials1 != null : "Expected valid credentials to be found!"; URL newURL = new URL("http://localhost:8181/test/"); props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, newURL.toExternalForm()); connFactory.updated("pid1", props); UrlCredentials credentials2 = connFactory.getCredentials(TEST_URL); assert credentials2 == null : "Expected no credentials to be found!"; credentials2 = connFactory.getCredentials(newURL); assert credentials2 != null : "Expected valid credentials to be found!"; assert credentials1 != credentials2 && !credentials1.equals(credentials2) : "Expected not the same credentials to be returned!"; }