private File getCreatedTempDir(File workingDir) { assertThat(workingDir).isDirectory(); assertThat(workingDir.listFiles()).hasSize(1); return workingDir.listFiles()[0]; }
@Test public void create_array_of_patterns() { PathPattern[] patterns = PathPattern.create(new String[] { "**/src/main/**Foo.java", "file:**/src/main/**Bar.java" }); assertThat(patterns).hasSize(2); assertThat(patterns[0].toString()).isEqualTo("**/src/main/**Foo.java"); assertThat(patterns[1].toString()).isEqualTo("file:**/src/main/**Bar.java"); } }
@Test public void clean_temporary_files_at_startup() throws Exception { touch(new File(downloadDir, "sonar-php.jar")); touch(new File(downloadDir, "sonar-js.jar.tmp")); assertThat(downloadDir.listFiles()).hasSize(2); pluginDownloader.start(); File[] files = downloadDir.listFiles(); assertThat(files).hasSize(1); assertThat(files[0].getName()).isEqualTo("sonar-php.jar"); }
@Test public void methodWithRolesAllowedHasCorrectAttribute() throws Exception { ConfigAttribute[] accessAttributes = findAttributes("adminMethod"); assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ROLE_ADMIN"); }
@Test public void permitAllMethodHasPermitAllAttribute() throws Exception { ConfigAttribute[] accessAttributes = findAttributes("permitAllMethod"); assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()) .isEqualTo("javax.annotation.security.PermitAll"); }
@Test public void alreadyHasDefaultPrefix() throws Exception { ConfigAttribute[] accessAttributes = findAttributes("roleAdminMethod"); assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ROLE_ADMIN"); }
@Test public void customAnnotationAtClassLevelIsDetected() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); }
@Test public void customAnnotationAtInterfaceLevelIsDetected() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); }
@Test public void shouldGenerateEncryptedText() throws CryptoException { String encrypt = aesEncrypter.encrypt("p@ssw0rd"); assertThat(encrypt).startsWith("AES"); assertThat(encrypt.split(":")).hasSize(3); }
@Test public void nullDefaultRolePrefix() throws Exception { this.mds.setDefaultRolePrefix(null); ConfigAttribute[] accessAttributes = findAttributes("adminMethod"); assertThat(accessAttributes).hasSize(1); assertThat(accessAttributes[0].toString()).isEqualTo("ADMIN"); }
@Test public void mixedClassAndMethodPreAnnotationsAreBothIncluded() { ConfigAttribute[] attrs = mds.getAttributes(voidImpl2).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression"); }
@Test public void classLevelPreAnnotationIsPickedUpWhenNoMethodLevelExists() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); assertThat(pre.getFilterExpression()).isNull(); }
@Test public void unzip_stream() throws Exception { InputStream zip = urlToZip().openStream(); File toDir = temp.newFolder(); ZipUtils.unzip(zip, toDir); assertThat(toDir.list()).hasSize(3); }
@Test public void targetDoesntLoseApplicationListenerInterface() { assertThat(appContext.getBeansOfType(ApplicationListener.class)).hasSize(1); assertThat(appContext.getBeanNamesForType(ApplicationListener.class)).hasSize(1); appContext.publishEvent(new AuthenticationSuccessEvent( new TestingAuthenticationToken("user", ""))); assertThat(target).isInstanceOf(ApplicationListener.class); }
@Test public void translate_offset_for_each_line() { Component component = createComponent(1); List<ScannerReport.LineSgnificantCode> significantCode = new ArrayList<>(); significantCode.add(createLineSignificantCode(1, 1, 2)); reportReader.putSignificantCode(component.getReportAttributes().getRef(), significantCode); assertThat(underTest.getRangesPerLine(component)).isNotEmpty(); LineRange[] lines = underTest.getRangesPerLine(component).get(); assertThat(lines).hasSize(1); assertThat(lines[0].startOffset()).isEqualTo(1); assertThat(lines[0].endOffset()).isEqualTo(2); }
@Test public void createTempFolderProps() throws Exception { File workingDir = temp.newFolder(); workingDir.delete(); TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath()))); tempFolder.newDir(); tempFolder.newFile(); assertThat(getCreatedTempDir(workingDir)).exists(); assertThat(getCreatedTempDir(workingDir).list()).hasSize(2); FileUtils.deleteQuietly(workingDir); }
@Test public void unzipping_creates_target_directory_if_it_does_not_exist() throws IOException { File zip = FileUtils.toFile(urlToZip()); File tempDir = temp.newFolder(); Files.delete(tempDir); File subDir = new File(tempDir, "subDir"); ZipUtils.unzip(zip, subDir); assertThat(subDir.list()).hasSize(3); }
@Test public void unzip_file() throws IOException { File zip = FileUtils.toFile(urlToZip()); File toDir = temp.newFolder(); ZipUtils.unzip(zip, toDir); assertThat(toDir.list()).hasSize(3); }
@Test public void annotatedAnnotationAtInterfaceLevelIsDetected() throws Exception { MockMethodInvocation annotatedAtInterfaceLevel = new MockMethodInvocation( new AnnotatedAnnotationAtInterfaceLevel(), ReturnVoid2.class, "doSomething", List.class); ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs).extracting("attribute").containsOnly("CUSTOM"); }
@Test public void annotatedAnnotationAtMethodLevelIsDetected() throws Exception { MockMethodInvocation annotatedAtMethodLevel = new MockMethodInvocation( new AnnotatedAnnotationAtMethodLevel(), ReturnVoid.class, "doSomething", List.class); ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs).extracting("attribute").containsOnly("CUSTOM"); }