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