userAuthenticationData.setData(new UserAuthenticationData.Type(type), data.toCharArray()); } else if (DATA.equals(localName)) { data = sb.toString();
elementType.setTextContent(type.toString()); Element elementData = document.createElement(DATA); elementData.setTextContent(value);
@Test(enabled = false) public void testSave() throws Exception { //given AuthStore authStore = new MemoryAuthStore(); UserAuthenticationDataWrapper authenticationData1 = new UserAuthenticationDataWrapper(); authenticationData1.setData(UserAuthenticationData.USERNAME, "Stefan".toCharArray()); authenticationData1.setData(UserAuthenticationData.PASSWORD, "Password".toCharArray()); authenticationData1.setData(new UserAuthenticationData.Type("path"), "c:\\file".toCharArray()); UserAuthenticationDataWrapper authenticationData2 = new UserAuthenticationDataWrapper(); authenticationData2.setData(UserAuthenticationData.USERNAME, "Stefaan".toCharArray()); authenticationData2.setData(UserAuthenticationData.PASSWORD, "Passwodrd".toCharArray()); authenticationData2.setData(UserAuthenticationData.DOMAIN, "MS".toCharArray()); UserAuthenticationDataWrapper authenticationData3 = new UserAuthenticationDataWrapper(); authenticationData3.setData(UserAuthenticationData.USERNAME, "Stefan".toCharArray()); authenticationData3.setData(UserAuthenticationData.PASSWORD, "Passwo@rd".toCharArray()); authenticationData3.setData(UserAuthenticationData.DOMAIN, "MSzx!X%a".toCharArray()); authStore.add(new UserAuthenticationInfo("ftp", "host1", "stefan"), authenticationData1); authStore.add(new UserAuthenticationInfo("ftp", "host1", "stefan9"), authenticationData1); authStore.add(new UserAuthenticationInfo("sftp", "host1a", "astefan"), authenticationData1); ByteArrayOutputStream bout = new ByteArrayOutputStream(); String expected = IOUtils.toString(this.getClass().getResourceAsStream("credentials.xml")); expected = expected.replaceAll(">\\s+", ">").replaceAll("\\s+<", "<").replaceAll("<Type>password</Type><Data>.*?<", "<Type>password</Type><Data><").trim(); //when authStoreUtils.save(authStore, bout); //then System.out.println(new String(bout.toByteArray())); String result = new String(bout.toByteArray()).replaceAll(">\\s+", ">").replaceAll("\\s+<", "<").replaceAll("<Type>password</Type><Data>.*?<", "<Type>password</Type><Data><").trim(); assertEquals(result, expected); }
@Test public void testLoad() throws Exception { //given MemoryAuthStore memoryAuthStore = new MemoryAuthStore(); InputStream resourceAsStream = this.getClass().getResourceAsStream("credentials.xml"); //when authStoreUtils.load(memoryAuthStore, resourceAsStream); //then assertEquals(memoryAuthStore.getAll().size(), 3); UserAuthenticationDataWrapper userAuthenticationData1 = memoryAuthStore.getUserAuthenticationData(new UserAuthenticationInfo("ftp", "host1", "stefan")); assertEquals(userAuthenticationData1.getData(UserAuthenticationData.USERNAME), "Stefan".toCharArray()); LOGGER.info("Password for stefan:" + new String(userAuthenticationData1.getData(UserAuthenticationData.PASSWORD))); assertEquals(userAuthenticationData1.getData(UserAuthenticationData.PASSWORD), "Password".toCharArray()); assertEquals(userAuthenticationData1.getData(new UserAuthenticationData.Type("path")), "c:\\file".toCharArray()); } }
@Test public void testCustomType() { final UserAuthenticationData.Type type = new UserAuthenticationData.Type("JUNIT"); final UserAuthenticationData data = new UserAuthenticationData(); final char[] array = "test".toCharArray(); data.setData(type, array); assertSame(array, data.getData(type)); } }
@Test public void testCustomType() { final UserAuthenticationData.Type type = new UserAuthenticationData.Type("JUNIT"); final UserAuthenticationData data = new UserAuthenticationData(); final char[] array = "test".toCharArray(); data.setData(type, array); assertSame(array, data.getData(type)); } }
@Test public void testCustomType() { final UserAuthenticationData.Type type = new UserAuthenticationData.Type("JUNIT"); final UserAuthenticationData data = new UserAuthenticationData(); final char[] array = "test".toCharArray(); data.setData(type, array); assertSame(array, data.getData(type)); } }