Search in sources :

Example 1 with TestAssetData

use of org.sonatype.nexus.repository.content.store.example.TestAssetData in project nexus-public by sonatype.

the class ExampleContentTestSupport method generateAsset.

protected TestAssetData generateAsset(final int repositoryId, final String path) {
    TestAssetData asset = new TestAssetData();
    asset.setRepositoryId(repositoryId);
    asset.setPath(path);
    asset.setKind("test");
    asset.setAttributes(newAttributes("asset"));
    asset.setLastUpdated(OffsetDateTime.now());
    return asset;
}
Also used : TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData)

Example 2 with TestAssetData

use of org.sonatype.nexus.repository.content.store.example.TestAssetData in project nexus-public by sonatype.

the class ExampleContentTestSupport method randomAsset.

protected TestAssetData randomAsset(final int repositoryId, final String kind) {
    TestAssetData asset = randomAsset(repositoryId);
    asset.setKind(kind);
    return asset;
}
Also used : TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData)

Example 3 with TestAssetData

use of org.sonatype.nexus.repository.content.store.example.TestAssetData in project nexus-public by sonatype.

the class AssetDAOTest method testFlaggedBrowsing.

@Test
public void testFlaggedBrowsing() {
    TestAssetData asset1 = randomAsset(repositoryId);
    TestAssetData asset2 = randomAsset(repositoryId);
    // make sure paths are different
    asset2.setPath(asset1.path() + "/2");
    try (DataSession<?> session = sessionRule.openSession(DEFAULT_DATASTORE_NAME)) {
        TestAssetDAO dao = session.access(TestAssetDAO.class);
        // our bespoke schema will be applied automatically via 'extendSchema'...
        dao.createAsset(asset1);
        dao.createAsset(asset2);
        assertThat(dao.browseFlaggedAssets(repositoryId, 10, null), emptyIterable());
        asset2.setTestFlag(true);
        dao.updateAssetFlag(asset2);
        assertThat(dao.browseFlaggedAssets(repositoryId, 10, null), contains(allOf(samePath(asset2), sameAttributes(asset2))));
        asset1.setTestFlag(true);
        dao.updateAssetFlag(asset1);
        asset2.setTestFlag(false);
        dao.updateAssetFlag(asset2);
        assertThat(dao.browseFlaggedAssets(repositoryId, 10, null), contains(allOf(samePath(asset1), sameAttributes(asset1))));
    }
}
Also used : TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData) TestAssetDAO(org.sonatype.nexus.repository.content.store.example.TestAssetDAO) Test(org.junit.Test)

Example 4 with TestAssetData

use of org.sonatype.nexus.repository.content.store.example.TestAssetData in project nexus-public by sonatype.

the class AssetDAOTest method testReadPathTest.

@Test
public void testReadPathTest() {
    TestAssetData asset1 = randomAsset(repositoryId);
    TestAssetData asset2 = randomAsset(repositoryId);
    // make sure paths are different
    asset2.setPath(asset1.path() + "/2");
    try (DataSession<?> session = sessionRule.openSession(DEFAULT_DATASTORE_NAME)) {
        TestAssetDAO dao = session.access(TestAssetDAO.class);
        // our bespoke schema will be applied automatically via 'extendSchema'...
        dao.createAsset(asset1);
        dao.createAsset(asset2);
        asset2.setTestFlag(true);
        dao.updateAssetFlag(asset2);
        TestAssetData test1 = dao.readPathTest(repositoryId, asset1.path()).orElse(null);
        TestAssetData test2 = dao.readPathTest(repositoryId, asset2.path()).orElse(null);
        assertThat(test1, notNullValue());
        assertThat(test1.getTestFlag(), equalTo(false));
        assertThat(test2, notNullValue());
        assertThat(test2.getTestFlag(), equalTo(true));
        Continuation<Asset> continuation = dao.browseFlaggedAssets(repositoryId, 10, null);
        assertThat(continuation.size(), equalTo(1));
        TestAssetData test3 = continuation.stream().filter(obj -> obj instanceof TestAssetData).map(obj -> (TestAssetData) obj).findFirst().orElseThrow(() -> new IllegalStateException("Expect asset not found"));
        assertThat(test3.getTestFlag(), equalTo(true));
    }
}
Also used : TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData) IsIterableContainingInOrder(org.hamcrest.collection.IsIterableContainingInOrder) AssetInfo(org.sonatype.nexus.repository.content.AssetInfo) EntityId(org.sonatype.nexus.common.entity.EntityId) TestContentRepositoryDAO(org.sonatype.nexus.repository.content.store.example.TestContentRepositoryDAO) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DEFAULT_DATASTORE_NAME(org.sonatype.nexus.datastore.api.DataStoreManager.DEFAULT_DATASTORE_NAME) Before(org.junit.Before) ImmutableSet.of(com.google.common.collect.ImmutableSet.of) UTC(org.sonatype.nexus.common.time.UTC) DataSession(org.sonatype.nexus.datastore.api.DataSession) Collections.emptyMap(java.util.Collections.emptyMap) TestComponentDAO(org.sonatype.nexus.repository.content.store.example.TestComponentDAO) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) TestAssetDAO(org.sonatype.nexus.repository.content.store.example.TestAssetDAO) Matchers.allOf(org.hamcrest.Matchers.allOf) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Asset(org.sonatype.nexus.repository.content.Asset) TestAssetBlobDAO(org.sonatype.nexus.repository.content.store.example.TestAssetBlobDAO) List(java.util.List) TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) ComponentDAOTest.browseComponents(org.sonatype.nexus.repository.content.store.ComponentDAOTest.browseComponents) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) AssetBlob(org.sonatype.nexus.repository.content.AssetBlob) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) DuplicateKeyException(org.sonatype.nexus.datastore.api.DuplicateKeyException) Matchers.is(org.hamcrest.Matchers.is) ComponentDAOTest.countComponents(org.sonatype.nexus.repository.content.store.ComponentDAOTest.countComponents) Collections(java.util.Collections) Continuation(org.sonatype.nexus.common.entity.Continuation) Arrays.stream(java.util.Arrays.stream) IsIterableContainingInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder) Collectors.summingInt(java.util.stream.Collectors.summingInt) TestAssetDAO(org.sonatype.nexus.repository.content.store.example.TestAssetDAO) Asset(org.sonatype.nexus.repository.content.Asset) Test(org.junit.Test)

Example 5 with TestAssetData

use of org.sonatype.nexus.repository.content.store.example.TestAssetData in project nexus-public by sonatype.

the class FormatStoreManagerTest method testBespokeOperations.

@Test
public void testBespokeOperations() {
    Injector injector = Guice.createInjector(new WireModule(new TestBespokeStoreModule(), new SessionModule(), new TransactionModule()));
    FormatStoreManager underTest = injector.getInstance(Key.get(FormatStoreManager.class, Names.named("test")));
    // our bespoke schema will be applied automatically via 'extendSchema'...
    ContentRepositoryStore<?> contentRepositoryStore = underTest.contentRepositoryStore(DEFAULT_DATASTORE_NAME);
    TestAssetStore assetStore = underTest.assetStore(DEFAULT_DATASTORE_NAME);
    ContentRepositoryData repository = new ContentRepositoryData();
    repository.setAttributes(new NestedAttributesMap("attributes", new HashMap<>()));
    repository.setConfigRepositoryId(new EntityUUID(combUUID()));
    contentRepositoryStore.createContentRepository(repository);
    TestAssetData asset = new TestAssetData();
    asset.setAttributes(new NestedAttributesMap("attributes", new HashMap<>()));
    asset.setRepositoryId(repository.repositoryId);
    asset.setPath("/path/to/asset");
    asset.setKind("test");
    asset.setLastUpdated(OffsetDateTime.now());
    assetStore.createAsset(asset);
    assertThat(assetStore.browseFlaggedAssets(repository.repositoryId, 10, null), is(emptyIterable()));
    asset.setTestFlag(true);
    assetStore.updateAssetFlag(asset);
    Optional<Asset> result = assetStore.browseFlaggedAssets(repository.repositoryId, 10, null).stream().findFirst();
    assertThat(result.get().path(), is("/path/to/asset"));
}
Also used : TestAssetData(org.sonatype.nexus.repository.content.store.example.TestAssetData) WireModule(org.eclipse.sisu.wire.WireModule) TestAssetStore(org.sonatype.nexus.repository.content.store.example.TestAssetStore) HashMap(java.util.HashMap) TestBespokeStoreModule(org.sonatype.nexus.repository.content.store.example.TestBespokeStoreModule) NestedAttributesMap(org.sonatype.nexus.common.collect.NestedAttributesMap) EntityUUID(org.sonatype.nexus.common.entity.EntityUUID) Injector(com.google.inject.Injector) Asset(org.sonatype.nexus.repository.content.Asset) TransactionModule(org.sonatype.nexus.transaction.TransactionModule) Test(org.junit.Test)

Aggregations

TestAssetData (org.sonatype.nexus.repository.content.store.example.TestAssetData)6 Test (org.junit.Test)3 Asset (org.sonatype.nexus.repository.content.Asset)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet.of (com.google.common.collect.ImmutableSet.of)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Injector (com.google.inject.Injector)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneOffset (java.time.ZoneOffset)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1