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))));
}
}
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());
}
}
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));
}
}
Aggregations