Search in sources :

Example 46 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class AbstractSkimFunctionalTest method setupTestStores.

@Before
public void setupTestStores() throws Exception {
    final String changelog = "Create test structures";
    final String url = server.formatUrl(TEST_REPO);
    final RemoteRepository testRepo = client.stores().create(new RemoteRepository(TEST_REPO, url), changelog, RemoteRepository.class);
    Group g;
    if (client.stores().exists(group, PUBLIC)) {
        System.out.println("Loading pre-existing public group.");
        g = client.stores().load(group, PUBLIC, Group.class);
    } else {
        System.out.println("Creating new group 'public'");
        g = client.stores().create(new Group(PUBLIC), changelog, Group.class);
    }
    g.setConstituents(Collections.singletonList(testRepo.getKey()));
    client.stores().update(g, changelog);
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Before(org.junit.Before)

Example 47 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getRemoteRepository.

private RemoteRepository getRemoteRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getRemoteRepository: {})", key);
    RemoteRepository repo = (RemoteRepository) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", repo);
        return repo;
    }
    logger.debug("AutoProx decorator active");
    if (repo == null) {
        logger.info("AutoProx: creating repository for: {}", key);
        try {
            repo = catalog.createRemoteRepository(key);
            if (repo != null) {
                if (!checkValidity(key)) {
                    return null;
                }
                final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
                dataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating remote repository for: '" + key + "'"), false, true, eventMetadata);
            }
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new remote repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
    }
    return repo;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 48 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class AutoProxDataManagerDecoratorTest method repositoryNotAutoCreatedWhenTargetIsInvalid.

@Test
public void repositoryNotAutoCreatedWhenTargetIsInvalid() throws Exception {
    simpleCatalog();
    final String testUrl = http.formatUrl("target", "test");
    http.expect(testUrl, 404, "");
    catalog.setEnabled(false);
    assertThat(storeQuery.getRemoteRepository("test"), nullValue());
    catalog.setEnabled(true);
    final RemoteRepository repo = storeQuery.getRemoteRepository("test");
    assertThat(repo, nullValue());
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 49 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class AutoProxDataManagerDecoratorTest method repositoryAutoCreated.

@Test
public void repositoryAutoCreated() throws Exception {
    simpleCatalog();
    final String testUrl = http.formatUrl("target", "test");
    System.out.println("Registering expectation of GET/HEAD to: " + testUrl + "/ with 200 response code.");
    http.expect(testUrl + "/", 200, "");
    catalog.setEnabled(false);
    assertThat(storeQuery.getRemoteRepository("test"), nullValue());
    catalog.setEnabled(true);
    final RemoteRepository repo = storeQuery.getRemoteRepository("test");
    assertThat(repo, notNullValue());
    assertThat(repo.getName(), equalTo("test"));
    assertThat(repo.getUrl(), equalTo(testUrl));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 50 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class AutoProxDataManagerDecoratorTest method repositoryCreatedFromScannedDataDirRules.

@Test
public void repositoryCreatedFromScannedDataDirRules() throws Exception {
    final URL u = Thread.currentThread().getContextClassLoader().getResource("data/autoprox/simple-factory.groovy");
    final File f = new File(u.getPath());
    final File scriptFile = new File(autoproxDataDir, f.getName());
    FileUtils.copyFile(f, scriptFile);
    System.out.println("Parsing rules for: " + name.getMethodName());
    catalog.parseRules();
    final String testUrl = http.formatUrl("target", "test");
    logger.info("\n\nSETTING UP / VERIFYING REMOTE SERVER EXPECTATIONS");
    http.expect(testUrl + "/", 200, "");
    logger.info("DONE: SETTING UP / VERIFYING REMOTE SERVER EXPECTATIONS\n\n");
    catalog.setEnabled(false);
    assertThat(storeQuery.getRemoteRepository("test"), nullValue());
    catalog.setEnabled(true);
    final RemoteRepository repo = storeQuery.getRemoteRepository("test");
    assertThat(repo, notNullValue());
    assertThat(repo.getName(), equalTo("test"));
    assertThat(repo.getUrl(), equalTo(testUrl));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9