Search in sources :

Example 81 with Description

use of org.hamcrest.Description in project sonarqube by SonarSource.

the class ReportSubmitterTest method submit_a_report_on_existing_project.

@Test
public void submit_a_report_on_existing_project() {
    ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
    userSession.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    mockSuccessfulPrepareSubmitCall();
    underTest.submit(defaultOrganizationKey, project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verifyZeroInteractions(permissionTemplateService);
    verifyZeroInteractions(favoriteUpdater);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(project.uuid()) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) Test(org.junit.Test)

Example 82 with Description

use of org.hamcrest.Description in project sonarqube by SonarSource.

the class ReportSubmitterTest method provision_project_if_does_not_exist.

@Test
public void provision_project_if_does_not_exist() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    userSession.addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID).addPermission(PROVISION_PROJECTS, organization);
    mockSuccessfulPrepareSubmitCall();
    ComponentDto createdProject = newProjectDto(organization, PROJECT_UUID).setKey(PROJECT_KEY);
    when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject);
    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), anyInt(), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT))).thenReturn(true);
    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), eq(organization.getUuid()), any(ComponentDto.class))).thenReturn(true);
    underTest.submit(organization.getKey(), PROJECT_KEY, null, PROJECT_NAME, IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(PROJECT_UUID) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : DbSession(org.sonar.db.DbSession) NewComponent(org.sonar.server.component.NewComponent) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 83 with Description

use of org.hamcrest.Description in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method configure_http_proxy_credentials.

@Test
public void configure_http_proxy_credentials() {
    DefaultHttpDownloader.AuthenticatorFacade system = mock(DefaultHttpDownloader.AuthenticatorFacade.class);
    Settings settings = new MapSettings();
    settings.setProperty("https.proxyHost", "1.2.3.4");
    settings.setProperty("http.proxyUser", "the_login");
    settings.setProperty("http.proxyPassword", "the_passwd");
    new DefaultHttpDownloader.BaseHttpDownloader(system, settings, null);
    verify(system).setDefaultAuthenticator(argThat(new TypeSafeMatcher<Authenticator>() {

        @Override
        protected boolean matchesSafely(Authenticator authenticator) {
            DefaultHttpDownloader.ProxyAuthenticator a = (DefaultHttpDownloader.ProxyAuthenticator) authenticator;
            PasswordAuthentication authentication = a.getPasswordAuthentication();
            return authentication.getUserName().equals("the_login") && new String(authentication.getPassword()).equals("the_passwd");
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 84 with Description

use of org.hamcrest.Description in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method readStringWithTimeout.

@Test
public void readStringWithTimeout() throws URISyntaxException {
    thrown.expect(new BaseMatcher<Exception>() {

        @Override
        public boolean matches(Object ex) {
            return ex instanceof SonarException && ((SonarException) ex).getCause() instanceof SocketTimeoutException;
        }

        @Override
        public void describeTo(Description arg0) {
        }
    });
    new DefaultHttpDownloader(new MapSettings(), 50).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) Description(org.hamcrest.Description) MapSettings(org.sonar.api.config.MapSettings) SonarException(org.sonar.api.utils.SonarException) URI(java.net.URI) SonarException(org.sonar.api.utils.SonarException) URISyntaxException(java.net.URISyntaxException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 85 with Description

use of org.hamcrest.Description in project sonarqube by SonarSource.

the class ProjectBuilderMediumTest method testProjectReactorValidation.

@Test
public void testProjectReactorValidation() throws IOException {
    File baseDir = prepareProject();
    doThrow(new IllegalStateException("My error message")).when(projectBuilder).build(any(ProjectBuilder.Context.class));
    exception.expectMessage("Failed to execute project builder");
    exception.expect(MessageException.class);
    exception.expectCause(new BaseMatcher<Throwable>() {

        @Override
        public boolean matches(Object item) {
            if (!(item instanceof IllegalStateException)) {
                return false;
            }
            IllegalStateException e = (IllegalStateException) item;
            return "My error message".equals(e.getMessage());
        }

        @Override
        public void describeTo(Description description) {
        }
    });
    tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", ".").put("sonar.xoo.enableProjectBuilder", "true").build()).start();
}
Also used : Description(org.hamcrest.Description) File(java.io.File) Test(org.junit.Test)

Aggregations

Description (org.hamcrest.Description)122 Test (org.junit.Test)38 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)29 BaseMatcher (org.hamcrest.BaseMatcher)27 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6