SonarPlugin implements VisuwallPlugin<SonarConnection> { @Override public SoftwareId getSoftwareId(URL url, Map<String, String> properties) throws SoftwareNotFoundException { checkNotNull(url, "url is mandatory"); if (sonarDetector.isSonarPropertiesPage(url)) { return createSoftwareIdFromProperties(url); } else if (sonarDetector.isSonarWelcomePage(url)) { return createSoftwareIdFromWelcomePage(url); } throw new SoftwareNotFoundException("Url " + url.toString() + " is not compatible with Sonar"); } SonarPlugin(); @Override SonarConnection getConnection(URL url, Map<String, String> properties); @Override Class<SonarConnection> getConnectionClass(); @Override String getName(); @Override float getVersion(); @Override SoftwareId getSoftwareId(URL url, Map<String, String> properties); @Override String toString(); @Override Map<String, String> getPropertiesWithDefaultValue();  }
@Test(expected = NullPointerException.class) public void should_throw_exception_when_passing_null_to_is_sonar_instance() throws SoftwareNotFoundException { new SonarPlugin().getSoftwareId(null, properties); }
@Test(expected = SoftwareNotFoundException.class) public void should_throw_exception_if_url_is_not_sonar() throws Exception { when(client.exist(anyString(), any(Class.class))).thenReturn(false); URL url = new URL("http: sonar.getSoftwareId(url, properties); }
@Test(expected = SoftwareNotFoundException.class) public void should_throw_exception_if_there_is_no_properties_page() throws Exception { Object resourceCall = client.resource(anyString(), any(Class.class), eq(APPLICATION_XML_TYPE)); when(resourceCall).thenThrow(new ResourceNotFoundException("not found")); URL url = new URL("http: sonar.getSoftwareId(url, properties); }
@Test public void should_get_incompatible_property_when_version_is_inferior_of_24() throws Exception { when(sonarDetector.isSonarPropertiesPage(any(URL.class))).thenReturn(true); when(sonarVersionExtractor.propertiesVersion(any(Properties.class))).thenReturn("1.3"); URL url = new URL("http: SoftwareId softwareId = sonar.getSoftwareId(url, properties); assertFalse(softwareId.isCompatible()); assertEquals("Sonar version 1.3 is not compatible with Visuwall. Please use a version >= 2.4", softwareId.getWarnings()); }
@Test public void should_extract_version_from_welcome_page() throws Exception { when(sonarDetector.isSonarWelcomePage(any(URL.class))).thenReturn(true); when(sonarVersionExtractor.welcomePageVersion(any(URL.class))).thenReturn("2.5"); URL url = new URL("http: SoftwareId softwareId = sonar.getSoftwareId(url, properties); assertTrue(softwareId.isCompatible()); }