Package org.sonatype.nexus.configuration.model

Examples of org.sonatype.nexus.configuration.model.Configuration


  @Test
  public void testLoadConfiguration()
      throws Exception
  {
    // get it
    Configuration config = nexusConfiguration.getConfigurationModel();

    // check it for default value
    assertEquals("smtp-host", config.getSmtpConfiguration().getHostname());

    // modify it
    nexusEmailer.setSMTPHostname("NEW-HOST");

    // save it
    nexusConfiguration.saveConfiguration();

    FileUtils.copyInputStreamToFile(
        getClass().getResourceAsStream("/META-INF/nexus/nexus.xml"), new File(getNexusConfiguration())
    );

    // force reload
    nexusConfiguration.loadConfiguration(true);

    // get the config
    config = nexusConfiguration.getConfigurationModel();

    // it again contains default value, coz we overwritten it before
    assertEquals("smtp-host", config.getSmtpConfiguration().getHostname());
    assertEquals("smtp-host", nexusEmailer.getSMTPHostname());
  }
View Full Code Here


  @Test
  public void testNEXUS2212SaveInvalidConfig()
      throws Exception
  {
    Configuration nexusConfig = nexusConfiguration.getConfigurationModel();

    CRepository centralCRepo = null;

    for (CRepository cRepo : nexusConfig.getRepositories()) {
      if (cRepo.getId().equals("central")) {
        centralCRepo = cRepo;
        break;
      }
    }
View Full Code Here

  private void doTestLogic()
      throws Exception
  {
    ApplicationConfigurationSource source = this.getConfigSource();

    Configuration config = source.loadConfiguration();

    // make sure the smtp-password is what we expect
    Assert.assertEquals("Incorrect SMTP password found in nexus.xml", "smtp-password", config
        .getSmtpConfiguration().getPassword());

    // set the clear passwords
    String password = "clear-text";

    // smtp
    config.getSmtpConfiguration().setPassword(password);

    // global proxy
    config.setRemoteProxySettings(new CRemoteProxySettings());

    final CRemoteHttpProxySettings httpProxySettings = new CRemoteHttpProxySettings();
    httpProxySettings.setProxyHostname("localhost");
    httpProxySettings.setProxyPort(1234);
    httpProxySettings.setAuthentication(new CRemoteAuthentication());
    httpProxySettings.getAuthentication().setPassword(password);

    final CRemoteHttpProxySettings httpsProxySettings = new CRemoteHttpProxySettings();
    httpsProxySettings.setProxyHostname("localhost");
    httpsProxySettings.setProxyPort(1234);
    httpsProxySettings.setAuthentication(new CRemoteAuthentication());
    httpsProxySettings.getAuthentication().setPassword(password);

    config.getRemoteProxySettings().setHttpProxySettings(httpProxySettings);
    config.getRemoteProxySettings().setHttpsProxySettings(httpsProxySettings);

    //        config.getSecurity().setAnonymousPassword( password );
    //
    //        // anon username
    //        config.getSecurity().setAnonymousPassword( password );

    // repo auth pass
    CRepository central = this.getCentralRepo(config);
    central.getRemoteStorage().setAuthentication(new CRemoteAuthentication());
    central.getRemoteStorage().getAuthentication().setPassword(password);

    // now we need to make the file valid....
    config.getRemoteProxySettings().getHttpProxySettings().setProxyPort(1234);

    // save it
    source.storeConfiguration();

    XStream xs = new XStream();
    xs.processAnnotations(new Class[] { Xpp3Dom.class });
    Assert.assertTrue("Configuration is corroupt, passwords are encrypted (in memory). ",
        xs.toXML(config).contains(password));

    // now get the file and look for the "clear-text"
    String configString = FileUtils.readFileToString(new File(this.getNexusConfiguration()));

    Assert.assertFalse("Clear text password found in nexus.xml:\n" + configString, configString
        .contains(password));

    // make sure we do not have the default smtp password either
    Assert.assertFalse("Old SMTP password found in nexus.xml", configString.contains("smtp-password"));

    // now load it again and make sure the password is clear text
    Configuration newConfig = source.loadConfiguration();
    Assert.assertEquals(password, newConfig.getSmtpConfiguration().getPassword());
    Assert.assertEquals(
        password, newConfig.getRemoteProxySettings().getHttpProxySettings().getAuthentication().getPassword()
    );
    Assert.assertEquals(
        password, newConfig.getRemoteProxySettings().getHttpsProxySettings().getAuthentication().getPassword()
    );
    //        Assert.assertEquals( password, newConfig.getSecurity().getAnonymousPassword() );

    central = this.getCentralRepo(newConfig);
    Assert.assertEquals(password, central.getRemoteStorage().getAuthentication().getPassword());
View Full Code Here

  @Test
  public void sameMemberMultipleTime() {
    final Xpp3Dom xpp3Dom = mock(Xpp3Dom.class);
    final ApplicationConfiguration applicationConfiguration = mock(ApplicationConfiguration.class);
    final Configuration configuration = mock(Configuration.class);
    final CRepository repo1 = new CRepository();
    repo1.setId("1");
    final CRepository repo2 = new CRepository();
    repo2.setId("2");

    when(applicationConfiguration.getConfigurationModel()).thenReturn(configuration);
    when(configuration.getRepositories()).thenReturn(Lists.newArrayList(repo1, repo2));

    final AbstractGroupRepositoryConfiguration underTest = new AbstractGroupRepositoryConfiguration(
        xpp3Dom
    )
    {
View Full Code Here

  private void setupEmailConfig()
      throws IOException, XmlPullParserException
  {
    try (FileInputStream fis = new FileInputStream(this.getNexusConfiguration())) {
      NexusConfigurationXpp3Reader reader = new NexusConfigurationXpp3Reader();
      Configuration config = reader.read(fis);

      config.getSmtpConfiguration().setPort(this.emailServerPort);
      config.getSmtpConfiguration().setHostname("localhost");
      // config.getSmtpConfiguration().setDebugMode( true );

      // now write it back out
      try (FileWriter writer = new FileWriter(this.getNexusConfiguration())) {
        new NexusConfigurationXpp3Writer().write(writer, config);
View Full Code Here

  @Test
  public void modifyConfiguration()
      throws Exception
  {
    final Configuration configuration = new NexusConfigurationXpp3Reader().read(
        new FileInputStream(util.resolveFile("target/test-classes/nexus.xml"))
    );

    modifier.apply(configuration);
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.configuration.model.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.