@Override public SpiderDataRecord upload( String authToken, String type, String id, InputStream stream, String fileName) { this.authToken = authToken; this.recordType = type; tryToGetActiveUser(); checkUserIsAuthorizedForActionOnRecordType(); checkRecordTypeIsChildOfBinary(); DataGroup recordRead = recordStorage.read(type, id); spiderRecordRead = SpiderDataGroup.fromDataGroup(recordRead); checkUserIsAuthorisedToUploadData(recordRead); checkStreamIsPresent(stream); checkFileNameIsPresent(fileName); streamId = idGenerator.getIdForType(type + "Binary"); String dataDivider = extractDataDividerFromData(spiderRecordRead); long fileSize = streamStorage.store(streamId, dataDivider, stream); addOrReplaceResourceInfoToMetdataRecord(fileName, fileSize); SpiderRecordUpdater spiderRecordUpdater = SpiderInstanceProvider.getSpiderRecordUpdater(); return spiderRecordUpdater.updateRecord(userId, type, id, spiderRecordRead); }
@BeforeMethod public void beforeMethod() { SpiderInstanceFactory factory = SpiderInstanceFactoryImp.usingDependencyProvider(new DependencyProviderForTest()); SpiderInstanceProvider.setSpiderInstanceFactory(factory); UriInfo uriInfo = new TestUri(); recordEndpoint = new RecordEndpoint(uriInfo); }
@Test public void testCreateRecordUnexpectedError() { DependencyProviderForTest spiderDependencyProvider = new DependencyProviderForTest(); spiderDependencyProvider.setDataValidator(new DataValidatorReturnNullPointer()); SpiderInstanceFactory factory = SpiderInstanceFactoryImp.usingDependencyProvider(spiderDependencyProvider); SpiderInstanceProvider.setSpiderInstanceFactory(factory); response = recordEndpoint.createRecord(AUTH_TOKEN, AUTH_TOKEN, PLACE, jsonToCreateFrom); assertResponseStatusIs(Response.Status.INTERNAL_SERVER_ERROR); }
@Test public void testCreateRecordNotValid() { // uses always invalid validator DependencyProviderForTest spiderDependencyProvider = new DependencyProviderForTest(); spiderDependencyProvider.setDataValidator(new DataValidatorAlwaysInvalidSpy()); SpiderInstanceFactory factory = SpiderInstanceFactoryImp.usingDependencyProvider(spiderDependencyProvider); SpiderInstanceProvider.setSpiderInstanceFactory(factory); response = recordEndpoint.createRecord(AUTH_TOKEN, AUTH_TOKEN, PLACE, jsonToCreateFrom); assertResponseStatusIs(Response.Status.BAD_REQUEST); }
private SpiderInstanceFactorySpy setupInstanceProviderWithFactorySpy() { SpiderInstanceFactorySpy factorySpy = new SpiderInstanceFactorySpy(); SpiderInstanceProvider.setSpiderInstanceFactory(factorySpy); return factorySpy; }
private void setNotAuthorized() { SpiderInstanceFactory factory = SpiderInstanceFactoryImp.usingDependencyProvider( new DependencyProviderForTestNotAuthorized()); SpiderInstanceProvider.setSpiderInstanceFactory(factory); }