@Test public void testImportWhitelistedSites() throws IOException { WhitelistedSite site1 = new WhitelistedSite(); site1.setId(1L); site1.setClientId("foo"); WhitelistedSite site2 = new WhitelistedSite(); site2.setId(2L); site2.setClientId("bar"); WhitelistedSite site3 = new WhitelistedSite(); site3.setId(3L); site3.setClientId("baz"); String configJson = "{" + "\"" + MITREidDataService.CLIENTS + "\": [], " + "\"" + MITREidDataService.ACCESSTOKENS + "\": [], " + "\"" + MITREidDataService.REFRESHTOKENS + "\": [], " + "\"" + MITREidDataService.GRANTS + "\": [], " + "\"" + MITREidDataService.BLACKLISTEDSITES + "\": [], " + "\"" + MITREidDataService.SYSTEMSCOPES + "\": [], " + "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " + "\"" + MITREidDataService.WHITELISTEDSITES + "\": [" + "{\"id\":1,\"clientId\":\"foo\"}," + "{\"id\":2,\"clientId\":\"bar\"}," + "{\"id\":3,\"clientId\":\"baz\"}" + " ]" + "}"; System.err.println(configJson); JsonReader reader = new JsonReader(new StringReader(configJson)); final Map<Long, WhitelistedSite> fakeDb = new HashMap<Long, WhitelistedSite>(); when(wlSiteRepository.save(isA(WhitelistedSite.class))).thenAnswer(new Answer<WhitelistedSite>() { Long id = 333L; @Override public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable { WhitelistedSite _site = (WhitelistedSite) invocation.getArguments()[0]; if(_site.getId() == null) { _site.setId(id++); } fakeDb.put(_site.getId(), _site); return _site; } }); when(wlSiteRepository.getById(anyLong())).thenAnswer(new Answer<WhitelistedSite>() { @Override public WhitelistedSite answer(InvocationOnMock invocation) throws Throwable { Long _id = (Long) invocation.getArguments()[0]; return fakeDb.get(_id); } }); dataService.importData(reader); verify(wlSiteRepository, times(3)).save(capturedWhitelistedSites.capture()); List<WhitelistedSite> savedSites = capturedWhitelistedSites.getAllValues(); assertThat(savedSites.size(), is(3)); assertThat(savedSites.get(0).getClientId(), equalTo(site1.getClientId())); assertThat(savedSites.get(1).getClientId(), equalTo(site2.getClientId())); assertThat(savedSites.get(2).getClientId(), equalTo(site3.getClientId())); }
@Override public void importData(JsonReader reader) throws IOException { logger.info("Reading configuration for 1.0"); reader.beginObject(); while (reader.hasNext()) { JsonToken tok = reader.peek(); switch (tok) { case NAME: String name = reader.nextName(); if (name.equals(CLIENTS)) { readClients(reader); } else if (name.equals(GRANTS)) { readGrants(reader); } else if (name.equals(WHITELISTEDSITES)) { readWhitelistedSites(reader); } else if (name.equals(BLACKLISTEDSITES)) { readBlacklistedSites(reader); } else if (name.equals(AUTHENTICATIONHOLDERS)) { readAuthenticationHolders(reader); } else if (name.equals(ACCESSTOKENS)) { readAccessTokens(reader); } else if (name.equals(REFRESHTOKENS)) { readRefreshTokens(reader); } else if (name.equals(SYSTEMSCOPES)) { readSystemScopes(reader); } else { reader.skipValue(); } break; case END_OBJECT: reader.endObject(); continue; } } fixObjectReferences(); }
MITREidDataService_1_2 extends MITREidDataService_1_X { @Override public void importData(JsonReader reader) throws IOException { logger.info("Reading configuration for 1.0"); reader.beginObject(); while (reader.hasNext()) { JsonToken tok = reader.peek(); switch (tok) { case NAME: String name = reader.nextName(); if (name.equals(CLIENTS)) { readClients(reader); } else if (name.equals(GRANTS)) { readGrants(reader); } else if (name.equals(WHITELISTEDSITES)) { readWhitelistedSites(reader); } else if (name.equals(BLACKLISTEDSITES)) { readBlacklistedSites(reader); } else if (name.equals(AUTHENTICATIONHOLDERS)) { readAuthenticationHolders(reader); } else if (name.equals(ACCESSTOKENS)) { readAccessTokens(reader); } else if (name.equals(REFRESHTOKENS)) { readRefreshTokens(reader); } else if (name.equals(SYSTEMSCOPES)) { readSystemScopes(reader); } else { reader.skipValue(); } break; case END_OBJECT: reader.endObject(); continue; } } fixObjectReferences(); } }
MITREidDataService_1_2 extends MITREidDataService_1_X { @Override public void importData(JsonReader reader) throws IOException { logger.info("Reading configuration for 1.0"); reader.beginObject(); while (reader.hasNext()) { JsonToken tok = reader.peek(); switch (tok) { case NAME: String name = reader.nextName(); if (name.equals(CLIENTS)) { readClients(reader); } else if (name.equals(GRANTS)) { readGrants(reader); } else if (name.equals(WHITELISTEDSITES)) { readWhitelistedSites(reader); } else if (name.equals(BLACKLISTEDSITES)) { readBlacklistedSites(reader); } else if (name.equals(AUTHENTICATIONHOLDERS)) { readAuthenticationHolders(reader); } else if (name.equals(ACCESSTOKENS)) { readAccessTokens(reader); } else if (name.equals(REFRESHTOKENS)) { readRefreshTokens(reader); } else if (name.equals(SYSTEMSCOPES)) { readSystemScopes(reader); } else { reader.skipValue(); } break; case END_OBJECT: reader.endObject(); continue; } } fixObjectReferences(); }  }
MITREidDataService_1_2 extends MITREidDataService_1_X { @Override public void importData(JsonReader reader) throws IOException { logger.info("Reading configuration for 1.0"); reader.beginObject(); while (reader.hasNext()) { JsonToken tok = reader.peek(); switch (tok) { case NAME: String name = reader.nextName(); if (name.equals(CLIENTS)) { readClients(reader); } else if (name.equals(GRANTS)) { readGrants(reader); } else if (name.equals(WHITELISTEDSITES)) { readWhitelistedSites(reader); } else if (name.equals(BLACKLISTEDSITES)) { readBlacklistedSites(reader); } else if (name.equals(AUTHENTICATIONHOLDERS)) { readAuthenticationHolders(reader); } else if (name.equals(ACCESSTOKENS)) { readAccessTokens(reader); } else if (name.equals(REFRESHTOKENS)) { readRefreshTokens(reader); } else if (name.equals(SYSTEMSCOPES)) { readSystemScopes(reader); } else { reader.skipValue(); } break; case END_OBJECT: reader.endObject(); continue; } } fixObjectReferences(); }  @Override void exportData(JsonWriter writer); @Override void importData(JsonReader reader); }
MITREidDataService_1_2 extends MITREidDataService_1_X { @Override public void importData(JsonReader reader) throws IOException { logger.info("Reading configuration for 1.0"); reader.beginObject(); while (reader.hasNext()) { JsonToken tok = reader.peek(); switch (tok) { case NAME: String name = reader.nextName(); if (name.equals(CLIENTS)) { readClients(reader); } else if (name.equals(GRANTS)) { readGrants(reader); } else if (name.equals(WHITELISTEDSITES)) { readWhitelistedSites(reader); } else if (name.equals(BLACKLISTEDSITES)) { readBlacklistedSites(reader); } else if (name.equals(AUTHENTICATIONHOLDERS)) { readAuthenticationHolders(reader); } else if (name.equals(ACCESSTOKENS)) { readAccessTokens(reader); } else if (name.equals(REFRESHTOKENS)) { readRefreshTokens(reader); } else if (name.equals(SYSTEMSCOPES)) { readSystemScopes(reader); } else { reader.skipValue(); } break; case END_OBJECT: reader.endObject(); continue; } } fixObjectReferences(); }  @Override void exportData(JsonWriter writer); @Override void importData(JsonReader reader);  }