package org.carlspring.strongbox.storage.repository;

import org.carlspring.strongbox.storage.Storage;
import org.carlspring.strongbox.xml.parsers.GenericParser;

import javax.xml.bind.JAXBException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import static org.junit.Assert.assertTrue;

/**
 * @author carlspring
 */
public class RepositoryTest
{


    @Test
    public void testRepositoryWithCustomConfiguration()
            throws JAXBException
    {
        Storage storage = new Storage("aws-test-storage");
        Repository repository = new Repository("test-repository");
        repository.setStorage(storage);

        AwsConfiguration awsConfiguration = new AwsConfiguration();
        awsConfiguration.setBucket("test-bucket");
        awsConfiguration.setKey("test-key");

        GoogleCloudConfiguration googleCloudConfiguration = new GoogleCloudConfiguration();
        googleCloudConfiguration.setBucket("test-bucket");
        googleCloudConfiguration.setKey("test-key");

        List<CustomConfiguration> customConfigurations = new ArrayList<>();
        customConfigurations.add(awsConfiguration);
        customConfigurations.add(googleCloudConfiguration);

        repository.setCustomConfigurations(customConfigurations);

        GenericParser<Repository> parser = new GenericParser<>(Repository.class,
                                                               AwsConfiguration.class,
                                                               GoogleCloudConfiguration.class);
        String serialized = parser.serialize(repository);

        System.out.println(serialized);

        assertTrue(serialized.contains("<aws-configuration bucket=\"test-bucket\" key=\"test-key\"/>"));
        assertTrue(serialized.contains("<google-cloud-configuration bucket=\"test-bucket\" key=\"test-key\"/>"));
    }

}

@@ -83,463 +83,2377 @@
 box.
-storage.Storage;%0Aimport org.carlspring.strongbox.xml.parsers.GenericParser;%0A%0Aimport javax.xml.bind.JAXBException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.junit.Test;%0Aimport static org.junit.Assert.assertTrue;%0A%0A/**%0A * @author carlspring%0A */%0Apublic class RepositoryTest%0A%7B%0A%0A%0A    @Test%0A    public void testRepositoryWithCustomConfiguration()%0A            throws JAXBException%0A    %7B%0A        Storage storage = new Storage(%22aws-test-storage
+config.ClientConfig;%0Aimport org.carlspring.strongbox.config.CommonConfig;%0Aimport org.carlspring.strongbox.config.DataServiceConfig;%0Aimport org.carlspring.strongbox.config.StorageApiConfig;%0Aimport org.carlspring.strongbox.configuration.ConfigurationManager;%0Aimport org.carlspring.strongbox.storage.Storage;%0Aimport org.carlspring.strongbox.xml.parsers.GenericParser;%0A%0Aimport javax.xml.bind.JAXBException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.context.annotation.Import;%0Aimport org.springframework.test.context.ContextConfiguration;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0Aimport static org.junit.Assert.assertTrue;%0A%0A/**%0A * @author carlspring%0A */%0A//@RunWith(SpringJUnit4ClassRunner.class)%0A//@ContextConfiguration%0Apublic class RepositoryTest%0A%7B%0A%0A/*%0A    @org.springframework.context.annotation.Configuration%0A    @Import(%7B StorageApiConfig.class,%0A              CommonConfig.class,%0A              ClientConfig.class,%0A              DataServiceConfig.class%0A            %7D)%0A    public static class SpringConfig %7B %7D%0A%0A    @Autowired%0A    private ConfigurationManager configurationManager;%0A*/%0A%0A%0A    @Test%0A    public void testRepositoryWithCustomConfiguration()%0A            throws JAXBException%0A    %7B%0A        Repository repository = createTestRepository();%0A%0A        GenericParser%3CRepository%3E parser = new GenericParser%3C%3E(Repository.class,%0A                                                               AwsConfiguration.class,%0A                                                               GoogleCloudConfiguration.class);%0A        String serialized = parser.serialize(repository);%0A%0A        System.out.println(serialized);%0A%0A        assertTrue(serialized.contains(%22%3Caws-configuration bucket=%5C%22test-bucket%5C%22 key=%5C%22test-key%5C%22/%3E%22));%0A        assertTrue(serialized.contains(%22%3Cgoogle-cloud-configuration bucket=%5C%22test-bucket%5C%22 key=%5C%22test-key%5C%22/%3E%22));%0A    %7D%0A%0A    @Test%0A    public void testAddRepositoryWithCustomConfiguration()%0A    %7B%0A        Repository repository = createTestRepository();%0A%0A        // configurationManager.getConfiguration().getStorage(%22storage0%22).addOrUpdateRepository(repository);%0A    %7D%0A%0A    private Repository createTestRepository()%0A    %7B%0A        Storage storage = new Storage(%22storage0
 %22);%0A
@@ -3198,581 +3198,25 @@
     
-GenericParser%3CRepository%3E parser = new GenericParser%3C%3E(Repository.class,%0A                                                               AwsConfiguration.class,%0A                                                               GoogleCloudConfiguration.class);%0A        String serialized = parser.serialize(repository);%0A%0A        System.out.println(serialized);%0A%0A        assertTrue(serialized.contains(%22%3Caws-configuration bucket=%5C%22test-bucket%5C%22 key=%5C%22test-key%5C%22/%3E%22));%0A        assertTrue(serialized.contains(%22%3Cgoogle-cloud-configuration bucket=%5C%22test-bucket%5C%22 key=%5C%22test-key%5C%22/%3E%22))
+return repository
 ;%0A  

Make it possible to specify custom configuration for repositories