use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class MachineServiceLinksInjectorTest method shouldInjectLinksIntoMachineDto.
@Test
public void shouldInjectLinksIntoMachineDto() {
when(terminalServerMock.getRef()).thenReturn(TERMINAL_REFERENCE);
when(terminalServerMock.getUrl()).thenReturn(URI_BASE + "/pty");
when(execAgentServerMock.getRef()).thenReturn(EXEC_AGENT_REFERENCE);
when(execAgentServerMock.getUrl()).thenReturn(URI_BASE + "/connect");
when(machineRuntimeInfoDtoMock.getServers()).thenReturn(ImmutableMap.of(TERMINAL_REFERENCE, terminalServerMock, EXEC_AGENT_REFERENCE, execAgentServerMock));
final MachineDto machineDto = DtoFactory.newDto(MachineDto.class).withId("id").withWorkspaceId("wsId").withConfig(machineConfigDtoMock).withRuntime(machineRuntimeInfoDtoMock);
machineLinksInjector.injectLinks(machineDto, serviceContextMock);
final Set<Pair<String, String>> links = machineDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", TERMINAL_REFERENCE), Pair.of("GET", EXEC_AGENT_REFERENCE), Pair.of("GET", LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL), Pair.of("GET", ENVIRONMENT_STATUS_CHANNEL_TEMPLATE)));
assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class FactoryDaoTest method shouldGetFactoryByIdAttribute.
@Test
public void shouldGetFactoryByIdAttribute() throws Exception {
final FactoryImpl factory = factories[0];
final List<Pair<String, String>> attributes = ImmutableList.of(Pair.of("id", factory.getId()));
final List<FactoryImpl> result = factoryDao.getByAttribute(1, 0, attributes);
assertEquals(new HashSet<>(result), ImmutableSet.of(factory));
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class FactoryService method getFactoryByAttribute.
@GET
@Path("/find")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get factory by attribute, " + "the attribute must match one of the Factory model fields with type 'String', " + "e.g. (factory.name, factory.creator.name)", notes = "If specify more than one value for a single query parameter then will be taken the first one")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains list requested factories"), @ApiResponse(code = 400, message = "When query does not contain at least one attribute to search for"), @ApiResponse(code = 500, message = "Internal server error") })
public List<FactoryDto> getFactoryByAttribute(@DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @DefaultValue("30") @QueryParam("maxItems") Integer maxItems, @Context UriInfo uriInfo) throws BadRequestException, ServerException {
final Set<String> skip = ImmutableSet.of("token", "skipCount", "maxItems");
final List<Pair<String, String>> query = URLEncodedUtils.parse(uriInfo.getRequestUri()).entrySet().stream().filter(param -> !skip.contains(param.getKey()) && !param.getValue().isEmpty()).map(entry -> Pair.of(entry.getKey(), entry.getValue().iterator().next())).collect(toList());
checkArgument(!query.isEmpty(), "Query must contain at least one attribute");
final List<FactoryDto> factories = new ArrayList<>();
for (Factory factory : factoryManager.getByAttribute(maxItems, skipCount, query)) {
factories.add(injectLinks(asDto(factory), null));
}
return factories;
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class JpaTckModule method configure.
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(UserImpl.class, ProfileImpl.class, PreferenceEntity.class, AccountImpl.class).setExceptionHandler(H2ExceptionHandler.class).build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server.getDataSource()));
bind(new TypeLiteral<TckRepository<UserImpl>>() {
}).to(UserJpaTckRepository.class);
bind(new TypeLiteral<TckRepository<ProfileImpl>>() {
}).toInstance(new JpaTckRepository<>(ProfileImpl.class));
bind(new TypeLiteral<TckRepository<Pair<String, Map<String, String>>>>() {
}).to(PreferenceJpaTckRepository.class);
bind(UserDao.class).to(JpaUserDao.class);
bind(ProfileDao.class).to(JpaProfileDao.class);
bind(PreferenceDao.class).to(JpaPreferenceDao.class);
// SHA-512 encryptor is faster than PBKDF2 so it is better for testing
bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);
}
use of org.eclipse.che.commons.lang.Pair in project che by eclipse.
the class ProfileLinksInjectorTest method shouldInjectProfileLinks.
@Test
public void shouldInjectProfileLinks() throws Exception {
final ProfileDto profileDto = DtoFactory.newDto(ProfileDto.class).withUserId("user123").withEmail("user@codenvy.com");
linksInjector.injectLinks(profileDto, serviceContext);
// [rel, method] pairs links
final Set<Pair<String, String>> links = profileDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", Constants.LINK_REL_SELF), Pair.of("GET", Constants.LINK_REL_CURRENT_PROFILE), Pair.of("PUT", Constants.LINK_REL_PROFILE_ATTRIBUTES), Pair.of("PUT", Constants.LINK_REL_CURRENT_PROFILE_ATTRIBUTES), Pair.of("DELETE", Constants.LINK_REL_CURRENT_PROFILE_ATTRIBUTES)));
assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Aggregations