List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:com.notonthehighstreet.ratel.internal.utility.HttpRequestTest.java
@Test public void callShouldMakeHTTPRequest() throws Exception { final String method = "GET"; final String parameterName = "name"; final String parameterValue = "value"; final Object body = new Object(); final int expected = 123123; final HttpURLConnection connection = mock(HttpURLConnection.class); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); when(connection.getOutputStream()).thenReturn(outputStream); when(connection.getResponseCode()).thenReturn(expected); final int actual = subject.call(connection, method, Collections.singletonMap(parameterName, parameterValue), body);//from w w w.j av a2 s. c om assertEquals(expected, actual); verify(mapper).writeValue(same(outputStream), same(body)); verify(connection).setRequestMethod(eq(method)); verify(connection).setReadTimeout(anyInt()); verify(connection).setConnectTimeout(anyInt()); verify(connection).setDoOutput(eq(true)); verify(connection).setRequestProperty(eq(parameterName), eq(parameterValue)); }
From source file:com.epam.ta.reportportal.database.dao.MongoDbTests.java
@Test public void checkFindById() { final String DEFAULT_PROJECT = "default_project"; Assert.assertNotNull(projectRepository); mongoTemplate.dropCollection(Project.class); mongoTemplate.dropCollection(User.class); User user = new User(); user.setLogin("default"); user.setPassword("3fde6bb0541387e4ebdadf7c2ff31123"); user.setType(UserType.INTERNAL); user.setDefaultProject(DEFAULT_PROJECT); user.getMetaInfo().setLastLogin(Calendar.getInstance().getTime()); user.setRole(UserRole.ADMINISTRATOR); user.setEmail("TesterUsername@epam.com"); user.setFullName("RP Tester"); userRepository.save(user);//from w w w.ja va 2 s . c o m Project project = new Project(); project.setCustomer("some customer"); project.setName(DEFAULT_PROJECT); project.setAddInfo("some additional info"); project.setUsers(Collections.singletonMap(user.getId(), Project.UserConfig.newOne() .withProjectRole(ProjectRole.MEMBER).withProposedRole(ProjectRole.MEMBER))); projectRepository.save(project); Project savedProject = projectRepository.findOne(project.getName()); Assert.assertNotNull(savedProject); Assert.assertTrue(projectRepository.isAssignedToProject(project.getName(), user.getLogin())); }
From source file:ru.mystamps.web.dao.impl.JdbcStampsCatalogDao.java
public List<String> findBySeriesId(Integer seriesId) { return jdbcTemplate.queryForList(findBySeriesIdSql, Collections.singletonMap("series_id", seriesId), String.class); }
From source file:org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient.java
@Override public SchemaRegistrationResponse register(String subject, String format, String schema) { Assert.isTrue("avro".equals(format), "Only Avro is supported"); String path = String.format("/subjects/%s", subject); HttpHeaders headers = new HttpHeaders(); headers.put("Accept", Arrays.asList("application/vnd.schemaregistry.v1+json", "application/vnd.schemaregistry+json", "application/json")); headers.add("Content-Type", "application/json"); Integer version = null;//from www. ja v a 2 s . c o m try { String payload = this.mapper.writeValueAsString(Collections.singletonMap("schema", schema)); HttpEntity<String> request = new HttpEntity<>(payload, headers); ResponseEntity<Map> response = this.template.exchange(this.endpoint + path, HttpMethod.POST, request, Map.class); version = (Integer) response.getBody().get("version"); } catch (JsonProcessingException e) { e.printStackTrace(); } SchemaRegistrationResponse schemaRegistrationResponse = new SchemaRegistrationResponse(); schemaRegistrationResponse.setId(version); schemaRegistrationResponse.setSchemaReference(new SchemaReference(subject, version, "avro")); return schemaRegistrationResponse; }
From source file:com.thoughtworks.go.spark.RoutesHelper.java
private void unprocessableEntity(UnprocessableEntityException exception, Request request, Response response) { response.body(new Gson().toJson(Collections.singletonMap("message", "Your request could not be processed. " + exception.getMessage()))); response.status(HttpStatus.SC_UNPROCESSABLE_ENTITY); }
From source file:com.hp.autonomy.frontend.find.idol.configuration.IdolConfigurationController.java
@SuppressWarnings("ProhibitedExceptionDeclared") @RequestMapping(value = "/config", method = { RequestMethod.POST, RequestMethod.PUT }) public ResponseEntity<?> saveConfig(@RequestBody final IdolFindConfigWrapper configResponse) throws Exception { log.info(Markers.AUDIT, "REQUESTED UPDATE CONFIGURATION"); try {//from w w w .j a va 2 s . co m configService.updateConfig(configResponse.getConfig()); final Object response = configService.getConfigResponse(); log.info(Markers.AUDIT, "UPDATED CONFIGURATION"); return new ResponseEntity<>(response, HttpStatus.OK); } catch (final ConfigException ce) { return new ResponseEntity<>(Collections.singletonMap("exception", ce.getMessage()), HttpStatus.NOT_ACCEPTABLE); } catch (final ConfigValidationException cve) { return new ResponseEntity<>(Collections.singletonMap("validation", cve.getValidationErrors()), HttpStatus.NOT_ACCEPTABLE); } }
From source file:org.cloudfoundry.identity.uaa.integration.TestProfileEnvironment.java
private TestProfileEnvironment() { List<Resource> resources = new ArrayList<Resource>(); for (String location : DEFAULT_PROFILE_CONFIG_FILE_LOCATIONS) { location = environment.resolvePlaceholders(location); Resource resource = recourceLoader.getResource(location); if (resource != null && resource.exists()) { resources.add(resource);//from w ww .ja v a2s.co m } } YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(resources.toArray(new Resource[resources.size()])); factory.setDocumentMatchers(Collections.singletonMap("platform", environment.acceptsProfiles("postgresql") ? "postgresql" : "hsqldb")); factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE); Properties properties = factory.getObject(); logger.debug("Decoding environment properties: " + properties.size()); if (!properties.isEmpty()) { for (Enumeration<?> names = properties.propertyNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); String value = properties.getProperty(name); if (value != null) { properties.setProperty(name, environment.resolvePlaceholders(value)); } } if (properties.containsKey("spring_profiles")) { properties.setProperty(StandardEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, properties.getProperty("spring_profiles")); } // System properties should override the ones in the config file, so add it last environment.getPropertySources().addLast(new PropertiesPropertySource("uaa.yml", properties)); } EnvironmentPropertiesFactoryBean environmentProperties = new EnvironmentPropertiesFactoryBean(); environmentProperties.setEnvironment(environment); environmentProperties.setDefaultProperties(properties); Map<String, ?> debugProperties = environmentProperties.getObject(); logger.debug("Environment properties: " + debugProperties); }
From source file:com.espertech.esper.regression.event.TestMapObjectArrayInterUse.java
public void testObjectArrayWithMap() { epService.getEPAdministrator().getConfiguration().addEventType("MapType", Collections.<String, Object>singletonMap("im", String.class)); epService.getEPAdministrator().getConfiguration().addEventType("OAType", "p0,p1,p2,p3".split(","), new Object[] { String.class, "MapType", "MapType[]", Collections.<String, Object>singletonMap("om", String.class) }); EPStatement stmt = epService.getEPAdministrator() .createEPL("select p0 as c0, p1.im as c1, p2[0].im as c2, p3.om as c3 from OAType"); stmt.addListener(listener);/*from w w w . ja va2s . c om*/ epService.getEPRuntime().sendEvent(new Object[] { "E1", Collections.singletonMap("im", "IM1"), new Map[] { Collections.singletonMap("im", "IM2") }, Collections.singletonMap("om", "OM1") }, "OAType"); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), "c0,c1,c2,c3".split(","), new Object[] { "E1", "IM1", "IM2", "OM1" }); epService.getEPAdministrator().destroyAllStatements(); // test inserting from array to map epService.getEPAdministrator().createEPL("insert into MapType(im) select p0 from OAType") .addListener(listener); epService.getEPRuntime().sendEvent(new Object[] { "E1" }, "OAType"); assertTrue(listener.assertOneGetNew() instanceof MapEventBean); assertEquals("E1", listener.assertOneGetNew().get("im")); }
From source file:org.cloudfoundry.identity.uaa.oauth.UaaUserApprovalHandlerTests.java
@Test public void testAutoApproveAll() { BaseClientDetails client = new BaseClientDetails("client", "none", "read,write", "authorization_code", "uaa.none"); client.setAdditionalInformation(Collections.singletonMap("autoapprove", true)); Mockito.when(clientDetailsService.loadClientByClientId("client")).thenReturn(client); assertTrue(handler.isApproved(authorizationRequest, userAuthentication)); }
From source file:org.cloudbyexample.dc.web.client.docker.ProvisionClient.java
/** * Create UUID request variable./* w w w. j ava 2 s.c o m*/ */ // FIXME: share public Map<String, String> createUuidVar(String uuid) { return Collections.singletonMap(ID_VAR, uuid); }