List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphabetic
public static String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alphabetic characters.
From source file:com.cws.esolutions.core.processors.impl.ServiceManagementProcessorImplTest.java
@Test public void addNewServiceAsDatacenter() { Service service = new Service(); service.setType(ServiceType.DATACENTER); service.setRegion(ServiceRegion.DEV); service.setName(RandomStringUtils.randomAlphabetic(8)); service.setStatus(ServiceStatus.ACTIVE); service.setDescription("Test Service X"); service.setPartition(NetworkPartition.DMZ); ServiceManagementRequest request = new ServiceManagementRequest(); request.setService(service);/*from ww w . j av a2 s .c o m*/ request.setRequestInfo(hostInfo); request.setServiceId("D1B5D088-32B3-4AA1-9FCF-822CB476B649"); request.setUserAccount(userAccount); request.setApplicationId("6236B840-88B0-4230-BCBC-8EC33EE837D9"); request.setApplicationName("eSolutions"); try { ServiceManagementResponse response = processor.addNewService(request); Assert.assertEquals(CoreServicesStatus.SUCCESS, response.getRequestStatus()); } catch (ServiceManagementException pmx) { Assert.fail(pmx.getMessage()); } }
From source file:com.funambol.foundation.util.FileDataObjectHelper.java
/** * Generate a temporary file name * @return */ private String getTempFileName() { return RandomStringUtils.randomAlphabetic(10) + ".tmp"; }
From source file:com.thebodgeitstore.selenium.tests.FunctionalSTest.java
@Test @Ignore/*from w w w. ja va 2 s. co m*/ public void tstRegisterUser() { // Create random username so we can rerun test String randomUser = RandomStringUtils.randomAlphabetic(10) + "@test.com"; this.registerUser(randomUser, "password"); assertTrue(DRIVER.getPageSource().indexOf("You have successfully registered with The BodgeIt Store.") > 0); }
From source file:com.thebodgeitstore.selenium.tests.FunctionalSTest.java
@Test @Ignore/*from ww w . ja v a 2 s. c o m*/ public void tstRegisterAndLoginUser() { // Create random username so we can rerun test String randomUser = RandomStringUtils.randomAlphabetic(10) + "@test.com"; this.registerUser(randomUser, "password"); assertTrue(DRIVER.getPageSource().indexOf("You have successfully registered with The BodgeIt Store.") > 0); checkMenu("Logout", "logout.jsp"); this.loginUser(randomUser, "password"); assertTrue(DRIVER.getPageSource().indexOf("You have logged in successfully:") > 0); }
From source file:info.archinnov.achilles.test.integration.tests.EventInterceptorIT.java
@Test public void should_apply_post_load_interceptor_on_slice_query() throws Exception { // Given// w w w . j a va 2s . c o m Long id = RandomUtils.nextLong(); Integer count = RandomUtils.nextInt(); String name = RandomStringUtils.randomAlphabetic(10); String value = "value_before_load"; ClusteredEntity entity = new ClusteredEntity(id, count, name, value); manager3.persist(entity); // When final List<ClusteredEntity> clusteredEntities = manager3.sliceQuery(ClusteredEntity.class) .partitionComponents(id).get(10); // Then assertThat(clusteredEntities.get(0).getValue()).isEqualTo("postLoad"); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.TagDAOImplTest.java
private static AppEntity createRandomApp(int index) throws Exception { String serverUserId = "serverUser"; String appName = APP_NAME_PREFIX + index; String appId = RandomStringUtils.randomAlphanumeric(10); String apiKey = UUID.randomUUID().toString(); String googleApiKey = UUID.randomUUID().toString(); String googleProjectId = RandomStringUtils.randomAlphanumeric(8); String apnsPwd = RandomStringUtils.randomAlphanumeric(10); String ownerId = RandomStringUtils.randomAlphabetic(10); String ownerEmail = RandomStringUtils.randomAlphabetic(4) + "@magnet.com"; String guestSecret = RandomStringUtils.randomAlphabetic(10); boolean apnsProductionEnvironment = false; AppEntity appEntity = new AppEntity(); appEntity.setServerUserId(serverUserId); appEntity.setName(appName);/*from w ww. ja v a 2 s .co m*/ appEntity.setAppId(appId); appEntity.setAppAPIKey(apiKey); appEntity.setGoogleAPIKey(googleApiKey); appEntity.setGoogleProjectId(googleProjectId); appEntity.setApnsCertPassword(apnsPwd); appEntity.setOwnerId(ownerId); appEntity.setOwnerEmail(ownerEmail); appEntity.setGuestSecret(guestSecret); appEntity.setApnsCertProduction(apnsProductionEnvironment); DBTestUtil.getAppDAO().persist(appEntity); return appEntity; }
From source file:com.aliyun.odps.mapred.bridge.LotMapperUDTFTest.java
@Test public void profile() throws Exception { conf.setMapperClass(WordCount.TokenizerMapper.class); conf.setCombinerClass(WordCount.SumCombiner.class); // conf.setCombinerClass(WordCount.SumCombiner.class); conf.setMapOutputKeySchema(SchemaUtils.fromString("word:string")); conf.setMapOutputValueSchema(SchemaUtils.fromString("count:bigint")); MockMapperUDTF udtf = new MockMapperUDTF(conf, testData); udtf.setup(ctx);/*from www . j av a 2s .com*/ Object[][] testData = new Object[100000][1]; for (int i = 0; i < 100000; i++) { testData[i] = new Object[] { RandomStringUtils.randomAlphabetic(5) }; } udtf.setTestData(testData); udtf.run(); udtf.close(); int sum = 0; for (Object[] item : udtf.getForwarded()) { sum += ((LongWritable) item[1]).get(); } assertEquals(100000, sum); }
From source file:com.kixeye.chassis.transport.HttpTransportTest.java
@Test public void testHttpServiceWithJson() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("http.enabled", "true"); properties.put("http.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("http.hostname", "localhost"); properties.put("websocket.enabled", "false"); properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("websocket.hostname", "localhost"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(TestRestService.class); try {/*from w w w. j a v a 2 s . c o m*/ context.refresh(); final MessageSerDe serDe = context.getBean(JsonJacksonMessageSerDe.class); RestTemplate httpClient = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); httpClient.setErrorHandler(new ResponseErrorHandler() { public boolean hasError(ClientHttpResponse response) throws IOException { return response.getRawStatusCode() == HttpStatus.OK.value(); } public void handleError(ClientHttpResponse response) throws IOException { } }); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); httpClient.setMessageConverters(new ArrayList<HttpMessageConverter<?>>( Lists.newArrayList(new SerDeHttpMessageConverter(serDe)))); TestObject response = httpClient.getForObject( new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("stuff", response.value); response = httpClient.postForObject( new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), new TestObject("more stuff"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("stuff", response.value); response = httpClient.getForObject( new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.getForObject( new URI("http://localhost:" + properties.get("http.port") + "/stuff/getFuture"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.getForObject( new URI("http://localhost:" + properties.get("http.port") + "/stuff/getObservable"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); ResponseEntity<ServiceError> error = httpClient.postForEntity( new URI("http://localhost:" + properties.get("http.port") + "/stuff/"), new TestObject(RandomStringUtils.randomAlphabetic(100)), ServiceError.class); Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.BAD_REQUEST, error.getStatusCode()); Assert.assertEquals(ExceptionServiceErrorMapper.VALIDATION_ERROR_CODE, error.getBody().code); error = httpClient.getForEntity( new URI("http://localhost:" + properties.get("http.port") + "/stuff/expectedError"), ServiceError.class); Assert.assertNotNull(response); Assert.assertEquals(TestRestService.EXPECTED_EXCEPTION_HTTP_CODE, error.getStatusCode()); Assert.assertEquals(TestRestService.EXPECTED_EXCEPTION.code, error.getBody().code); Assert.assertEquals(TestRestService.EXPECTED_EXCEPTION.description, error.getBody().description); error = httpClient.getForEntity( new URI("http://localhost:" + properties.get("http.port") + "/stuff/unexpectedError"), ServiceError.class); Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, error.getStatusCode()); Assert.assertEquals(ExceptionServiceErrorMapper.UNKNOWN_ERROR_CODE, error.getBody().code); } finally { context.close(); } }
From source file:gobblin.data.management.copy.writer.FileAwareInputStreamDataWriterTest.java
@Test public void testCommit() throws IOException { String destinationExistingToken = "destination"; String destinationAdditionalTokens = "path"; String fileName = "file"; // Asemble destination paths Path destination = new Path(new Path(new Path("/", destinationExistingToken), destinationAdditionalTokens), fileName);/*from w w w . ja v a2 s. c o m*/ Path destinationWithoutLeadingSeparator = new Path( new Path(destinationExistingToken, destinationAdditionalTokens), fileName); // Create temp directory File tmpFile = Files.createTempDir(); tmpFile.deleteOnExit(); Path tmpPath = new Path(tmpFile.getAbsolutePath()); // create origin file Path originFile = new Path(tmpPath, fileName); this.fs.createNewFile(originFile); // create stating dir Path stagingDir = new Path(tmpPath, "staging"); this.fs.mkdirs(stagingDir); // create output dir Path outputDir = new Path(tmpPath, "output"); this.fs.mkdirs(outputDir); // create copyable file FileStatus status = this.fs.getFileStatus(originFile); FsPermission readWrite = new FsPermission(FsAction.READ_WRITE, FsAction.READ_WRITE, FsAction.READ_WRITE); FsPermission dirReadWrite = new FsPermission(FsAction.ALL, FsAction.READ_WRITE, FsAction.READ_WRITE); OwnerAndPermission ownerAndPermission = new OwnerAndPermission(status.getOwner(), status.getGroup(), readWrite); List<OwnerAndPermission> ancestorOwnerAndPermissions = Lists.newArrayList(); ancestorOwnerAndPermissions.add(ownerAndPermission); ancestorOwnerAndPermissions.add(ownerAndPermission); ancestorOwnerAndPermissions.add(ownerAndPermission); ancestorOwnerAndPermissions.add(ownerAndPermission); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, "/publisher"); CopyableFile cf = CopyableFile .fromOriginAndDestination(this.fs, status, destination, CopyConfiguration.builder(FileSystem.getLocal(new Configuration()), properties) .publishDir(new Path("/target")).preserve(PreserveAttributes.fromMnemonicString("")) .build()) .destinationOwnerAndPermission(ownerAndPermission) .ancestorsOwnerAndPermission(ancestorOwnerAndPermissions).build(); // create work unit state WorkUnitState state = TestUtils.createTestWorkUnitState(); state.setProp(ConfigurationKeys.WRITER_STAGING_DIR, stagingDir.toUri().getPath()); state.setProp(ConfigurationKeys.WRITER_OUTPUT_DIR, outputDir.toUri().getPath()); state.setProp(ConfigurationKeys.WRITER_FILE_PATH, RandomStringUtils.randomAlphabetic(5)); CopyableDatasetMetadata metadata = new CopyableDatasetMetadata( new TestCopyableDataset(new Path("/source"))); CopySource.serializeCopyEntity(state, cf); CopySource.serializeCopyableDataset(state, metadata); // create writer FileAwareInputStreamDataWriter writer = new FileAwareInputStreamDataWriter(state, 1, 0); // create output of writer.write Path writtenFile = writer.getStagingFilePath(cf); this.fs.mkdirs(writtenFile.getParent()); this.fs.createNewFile(writtenFile); // create existing directories in writer output Path outputRoot = FileAwareInputStreamDataWriter.getPartitionOutputRoot(outputDir, cf.getDatasetAndPartition(metadata)); Path existingOutputPath = new Path(outputRoot, destinationExistingToken); this.fs.mkdirs(existingOutputPath); FileStatus fileStatus = this.fs.getFileStatus(existingOutputPath); FsPermission existingPathPermission = fileStatus.getPermission(); // check initial state of the relevant directories Assert.assertTrue(this.fs.exists(existingOutputPath)); Assert.assertEquals(this.fs.listStatus(existingOutputPath).length, 0); writer.actualProcessedCopyableFile = Optional.of(cf); // commit writer.commit(); // check state of relevant paths after commit Path expectedOutputPath = new Path(outputRoot, destinationWithoutLeadingSeparator); Assert.assertTrue(this.fs.exists(expectedOutputPath)); fileStatus = this.fs.getFileStatus(expectedOutputPath); Assert.assertEquals(fileStatus.getOwner(), ownerAndPermission.getOwner()); Assert.assertEquals(fileStatus.getGroup(), ownerAndPermission.getGroup()); Assert.assertEquals(fileStatus.getPermission(), readWrite); // parent should have permissions set correctly fileStatus = this.fs.getFileStatus(expectedOutputPath.getParent()); Assert.assertEquals(fileStatus.getPermission(), dirReadWrite); // previously existing paths should not have permissions changed fileStatus = this.fs.getFileStatus(existingOutputPath); Assert.assertEquals(fileStatus.getPermission(), existingPathPermission); Assert.assertFalse(this.fs.exists(writer.stagingDir)); }
From source file:com.frequentis.maritime.mcsr.web.rest.InstanceResourceIntTest.java
@Before public void initTest() throws TransformerException { instanceSearchRepository.deleteAll(); instance = new Instance(); // Common//from w ww .j av a 2s . c o m instance.setEndpointType(DEFAULT_ENDPOINT_TYPE); instance.setGeometryContentType(DEFAULT_GEOMETRY_CONTENT_TYPE); instance.setOrganizationId(DEFAULT_ORGANIZATION_ID); // All these field are overridden by XML (XML is required) instance.setName(DEFAULT_NAME); instance.setVersion(DEFAULT_VERSION); instance.setComment(DEFAULT_COMMENT); instance.setInstanceId(DEFAULT_INSTANCE_ID); instance.setKeywords(DEFAULT_KEYWORDS); instance.setStatus(DEFAULT_STATUS); instance.setUnlocode(DEFAULT_UNLOCODE); instance.setEndpointUri(DEFAULT_ENDPOINT_URI); // Create XML xmlSearchRepository.deleteAll(); Xml xml = new Xml(); xml.setName(DEFAULT_NAME); xml.setComment(DEFAULT_COMMENT); xml.setContentContentType(MediaType.APPLICATION_XML_VALUE); XMLInstanceBuilder xmlBuilder = new XMLInstanceBuilder(); InstanceXML x = xmlBuilder.getBuilderXml(); x.setName(DEFAULT_NAME); x.setDescription(DEFAULT_COMMENT); x.setURL(DEFAULT_ENDPOINT_URI); x.setKeywords(DEFAULT_KEYWORDS); x.setId(DEFAULT_INSTANCE_ID); x.setStatus(Status.valueOf(DEFAULT_STATUS)); x.setServiceType(DEFAULT_ENDPOINT_TYPE); x.setIMO(DEFAULT_IMO); x.setVersion(DEFAULT_VERSION); x.setMMSI(RandomStringUtils.randomAlphabetic(5)); x.setRequiresAuthorization("false"); VendorInfo producedBy = x.getProducedBy(); producedBy.setContactInfo(RandomStringUtils.randomAlphabetic(15)); producedBy.setName(RandomStringUtils.randomAlphabetic(15)); producedBy.setId(RandomStringUtils.randomAlphabetic(15)); producedBy.setOrganizationId(RandomStringUtils.randomAlphabetic(15)); producedBy.setDescription(RandomStringUtils.randomAlphabetic(15)); VendorInfo providedBy = x.getProvidedBy(); providedBy.setContactInfo(RandomStringUtils.randomAlphabetic(15)); providedBy.setName(RandomStringUtils.randomAlphabetic(15)); providedBy.setId(RandomStringUtils.randomAlphabetic(15)); providedBy.setOrganizationId(RandomStringUtils.randomAlphabetic(15)); providedBy.setDescription(RandomStringUtils.randomAlphabetic(15)); ServiceLevel offersServiceLevel = x.getOffersServiceLevel(); offersServiceLevel.setName(RandomStringUtils.randomAlphabetic(15)); offersServiceLevel.setAvailability(1); offersServiceLevel.setDescription(RandomStringUtils.randomAlphabetic(15)); CoversAreaType conversAreas = x.getCoversAreas(); // Requires plenty of heap (parsing JSON with unls) // conversAreas.setUnLoCode(DEFAULT_UNLOCODE); List<CoverageArea> coversArea = new ArrayList<>(); CoverageArea ca = new CoverageArea(); ca.setName("Bermuda Triangle"); ca.setDescription("Loosely defined region in the western part of the North Atlantic Ocean."); ca.setGeometryAsWKT("POLYGON((-80.190 25.774, -66.118 18.466, -64.757 32.321, -80.190 25.774))"); coversArea.add(ca); conversAreas.setCoversArea(coversArea); ServiceDesignReference implementsServiceDesign = x.getImplementsServiceDesign(); implementsServiceDesign.setId("awdwad"); implementsServiceDesign.setVersion("dwadwdwad"); xml.setContent(xmlBuilder.buildXmlString()); xmlService.save(xml); // Set XML instance.setInstanceAsXml(xml); }