use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class DirectoryListingDTOTest method jsonRoundTrip.
@Test
public void jsonRoundTrip() throws IOException {
DirectoryListingEntryDTO firstIn = new DirectoryListingEntryDTO(new StoreKey(StoreType.remote, "test"), "/this/is/a/path.pom");
DirectoryListingEntryDTO secondIn = new DirectoryListingEntryDTO(new StoreKey(StoreType.remote, "test"), "/this/is/another/path.pom");
DirectoryListingDTO in = new DirectoryListingDTO(Arrays.asList(firstIn, secondIn));
IndyObjectMapper mapper = new IndyObjectMapper(true);
String json = mapper.writeValueAsString(in);
DirectoryListingDTO out = mapper.readValue(json, DirectoryListingDTO.class);
assertThat(out, notNullValue());
List<DirectoryListingEntryDTO> items = out.getItems();
assertThat(items.size(), equalTo(2));
DirectoryListingEntryDTO firstOut = items.get(0);
assertThat(firstOut.getKey(), equalTo(firstIn.getKey()));
assertThat(firstOut.getPath(), equalTo(firstIn.getPath()));
DirectoryListingEntryDTO secondOut = items.get(1);
assertThat(secondOut.getKey(), equalTo(secondIn.getKey()));
assertThat(secondOut.getPath(), equalTo(secondIn.getPath()));
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class NotFoundCacheDTOTest method jsonRoundTrip.
@Test
public void jsonRoundTrip() throws IOException {
String firstSectionOnePath = "/path/to/first/file.pom";
String secondSectionOnePath = "/path/to/another/path.pom";
NotFoundCacheSectionDTO sectionOne = new NotFoundCacheSectionDTO(new StoreKey(StoreType.remote, "test"), Arrays.asList(firstSectionOnePath, secondSectionOnePath));
String firstSectionTwoPath = "/path/to/third/file.pom";
String secondSectionTwoPath = "/path/to/fourth/path.pom";
NotFoundCacheSectionDTO sectionTwo = new NotFoundCacheSectionDTO(new StoreKey(StoreType.remote, "test2"), Arrays.asList(firstSectionTwoPath, secondSectionTwoPath));
NotFoundCacheDTO in = new NotFoundCacheDTO();
in.addSection(sectionOne);
in.addSection(sectionTwo);
IndyObjectMapper mapper = new IndyObjectMapper(true);
String json = mapper.writeValueAsString(in);
NotFoundCacheDTO out = mapper.readValue(json, NotFoundCacheDTO.class);
assertThat(out, notNullValue());
Set<NotFoundCacheSectionDTO> sections = out.getSections();
assertThat(sections, notNullValue());
assertThat(sections.size(), equalTo(2));
assertThat(sections.contains(sectionOne), equalTo(true));
assertThat(sections.contains(sectionTwo), equalTo(true));
sections.forEach((section) -> {
StoreKey testKey;
Set<String> testPaths;
if (section.equals(sectionOne)) {
testKey = sectionOne.getKey();
testPaths = sectionOne.getPaths();
} else {
testKey = sectionTwo.getKey();
testPaths = sectionTwo.getPaths();
}
assertThat(section.getKey(), equalTo(testKey));
Set<String> paths = section.getPaths();
assertThat(paths, notNullValue());
assertThat(paths.size(), equalTo(testPaths.size()));
testPaths.forEach((path) -> {
assertThat(path + " NOT found in results for key: " + section.getKey(), paths.contains(path), equalTo(true));
});
});
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class GroupTest method copyFidelity.
@Test
public void copyFidelity() {
Group src = new Group(GENERIC_PKG_KEY, "test");
src.setMetadata("key", "value");
src.setDescription("some description");
src.setDisableTimeout(500);
src.setDisabled(true);
src.setTransientMetadata("transient", "someval");
src.setPathStyle(PathStyle.hashed);
src.addConstituent(new StoreKey(GENERIC_PKG_KEY, remote, "foo"));
Group target = src.copyOf();
Stream.of(Group.class.getMethods()).filter(m -> m.getName().startsWith("get") && m.isAccessible() && m.getParameterCount() == 0).forEach(m -> {
try {
assertThat(m.getName() + " didn't get copied correctly!", m.invoke(target), equalTo(m.invoke(src)));
} catch (IllegalAccessException e) {
e.printStackTrace();
fail("Failed to invoke: " + m.getName());
} catch (InvocationTargetException e) {
e.printStackTrace();
}
});
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class PromotionValidationTools method addLocations.
public void addLocations(final List<Location> locations, final StoreKey... extraLocations) throws IndyDataException {
for (StoreKey extra : extraLocations) {
ArtifactStore store = getArtifactStore(extra);
locations.add(LocationUtils.toLocation(store));
}
}
use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.
the class PromotionValidationTools method getValidationStoreKeys.
public StoreKey[] getValidationStoreKeys(final ValidationRequest request, final boolean includeSource, final boolean includeTarget) throws PromotionValidationException {
String verifyStores = request.getValidationParameter(PromotionValidationTools.AVAILABLE_IN_STORES);
if (verifyStores == null) {
verifyStores = request.getValidationParameter(PromotionValidationTools.AVAILABLE_IN_STORE_KEY);
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Got extra validation keys string: '{}'", verifyStores);
List<StoreKey> verifyStoreKeys = new ArrayList<>();
if (includeSource) {
verifyStoreKeys.add(request.getSourceRepository().getKey());
}
if (includeTarget) {
verifyStoreKeys.add(request.getTarget());
}
if (verifyStores == null) {
logger.warn("No external store (availableInStoreKey parameter) specified for validating path availability in rule-set: {}. Using target: {} instead.", request.getRuleSet().getName(), request.getTarget());
} else {
List<StoreKey> extras = Stream.of(verifyStores.split("\\s*,\\s*")).map(StoreKey::fromString).filter(item -> item != null).collect(Collectors.toList());
if (extras.isEmpty()) {
throw new PromotionValidationException("No valid StoreKey instances could be parsed from '%s'", verifyStores);
} else {
verifyStoreKeys.addAll(extras);
}
}
logger.debug("Using validation StoreKeys: {}", verifyStoreKeys);
return verifyStoreKeys.toArray(new StoreKey[verifyStoreKeys.size()]);
}
Aggregations