@Test public void fail_if_invalid_remediation_function() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to load the rule with key [squid:1]"); expectedException.expectCause(hasType(IllegalArgumentException.class) .andMessage("No enum constant org.sonar.api.server.debt.DebtRemediationFunction.Type.UNKNOWN")); load("" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>" + " <description>Desc</description>" + " <remediationFunction>UNKNOWN</remediationFunction>" + " </rule>" + "</rules>"); }
@Test public void retrieveSystemInfo_throws_ISE_if_http_error() { server.enqueue(new MockResponse().setResponseCode(500)); // initialize registration of process setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Failed to call HTTP server of process " + ProcessId.COMPUTE_ENGINE); expectedException.expectCause(hasType(IOException.class) .andMessage(format("Server returned HTTP response code: 500 for URL: http://%s:%d/systemInfo", server.getHostName(), server.getPort()))); underTest.retrieveSystemInfo(); }
@Test public void fail_if_unsupported_description_format() { String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>" + " <description>Desc</description>" + " <descriptionFormat>UNKNOWN</descriptionFormat>" + " </rule>" + "</rules>"; expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to load the rule with key [squid:1]"); expectedException.expectCause(hasType(IllegalArgumentException.class) .andMessage("No enum constant org.sonar.api.server.rule.RulesDefinitionXmlLoader.DescriptionFormat.UNKNOWN")); load(xml).rule("1"); }
@Test public void changeLogLevel_throws_ISE_if_http_error() { String message = "blah"; server.enqueue(new MockResponse().setResponseCode(500).setBody(message)); // initialize registration of process setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Failed to call HTTP server of process " + ProcessId.COMPUTE_ENGINE); expectedException.expectCause(hasType(IOException.class) .andMessage(format("Failed to change log level in Compute Engine. Code was '500' and response was 'blah' for url " + "'http://%s:%s/changeLogLevel'", server.getHostName(), server.getPort()))); underTest.changeLogLevel(LoggerLevel.DEBUG); }
@Test public void loads_duplication_with_otherFileRef_throws_IAE_if_references_itself() { int line = 2; reportReader.putDuplications(FILE_1_REF, createDuplication(singleLineTextRange(line), createInProjectDuplicate(FILE_1_REF, line + 1))); expectedException.expect(VisitException.class); expectedException.expectCause(hasType(IllegalArgumentException.class).andMessage("file and otherFile references can not be the same")); underTest.execute(new TestComputationStepContext()); }
@Test public void loads_duplication_with_otherFileRef_throws_IAE_if_component_does_not_exist() { int line = 2; reportReader.putDuplications(FILE_1_REF, createDuplication(singleLineTextRange(line), createInProjectDuplicate(666, line + 1))); expectedException.expect(VisitException.class); expectedException.expectCause(hasType(IllegalArgumentException.class).andMessage("Component with ref '666' can't be found")); underTest.execute(new TestComputationStepContext()); }
@Test public void fail_on_project_without_children_already_having_computed_measure() { ReportComponent root = builder(PROJECT, ROOT_REF).build(); treeRootHolder.setRoot(root); measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(10)); expectedException.expectCause(hasType(UnsupportedOperationException.class) .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY))); new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())) .visit(root); }
@Test public void fail_when_trying_to_compute_file_measure_already_existing_in_report() { ReportComponent root = builder(PROJECT, ROOT_REF) .addChildren( builder(Component.Type.FILE, FILE_1_REF).build()) .build(); treeRootHolder.setRoot(root); measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(2)); expectedException.expectCause(hasType(UnsupportedOperationException.class) .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY))); new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())) .visit(root); }