Search in sources :

Example 1 with TestAssetDAO

use of org.sonatype.nexus.repository.content.store.example.TestAssetDAO 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 2 with TestAssetDAO

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

the class AssetDAOTest method testFindByComponentIds.

@Test
public void testFindByComponentIds() {
    generateConfiguration();
    EntityId repositoryId = generatedConfigurations().get(0).getRepositoryId();
    generateSingleRepository(UUID.fromString(repositoryId.getValue()));
    generateContent(2);
    try (DataSession<?> session = sessionRule.openSession(DEFAULT_DATASTORE_NAME)) {
        TestAssetDAO dao = session.access(TestAssetDAO.class);
        Collection<AssetInfo> assets = dao.findByComponentIds(Collections.singleton(1));
        Optional<AssetInfo> assetOpt = assets.stream().findFirst();
        assertThat(assetOpt.isPresent(), is(true));
        AssetInfo asset = assetOpt.get();
        Asset generatedAsset = generatedAssets().get(0);
        AssetBlob generatedAssetBlob = generatedAssetBlobs().get(0);
        assertThat(asset.path(), is(generatedAsset.path()));
        assertThat(asset.contentType(), is(generatedAssetBlob.contentType()));
        assertThat(asset.lastUpdated(), notNullValue());
        assertThat(asset.checksums(), notNullValue());
    }
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) AssetBlob(org.sonatype.nexus.repository.content.AssetBlob) TestAssetDAO(org.sonatype.nexus.repository.content.store.example.TestAssetDAO) Asset(org.sonatype.nexus.repository.content.Asset) AssetInfo(org.sonatype.nexus.repository.content.AssetInfo) Test(org.junit.Test)

Example 3 with TestAssetDAO

use of org.sonatype.nexus.repository.content.store.example.TestAssetDAO 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)

Aggregations

Test (org.junit.Test)3 TestAssetDAO (org.sonatype.nexus.repository.content.store.example.TestAssetDAO)3 EntityId (org.sonatype.nexus.common.entity.EntityId)2 Asset (org.sonatype.nexus.repository.content.Asset)2 AssetBlob (org.sonatype.nexus.repository.content.AssetBlob)2 AssetInfo (org.sonatype.nexus.repository.content.AssetInfo)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 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 List (java.util.List)1 Optional (java.util.Optional)1