Esempio n. 1
0
  @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);
  }
Esempio n. 2
0
 @BeforeMethod
 public void beforeMethod() {
   SpiderInstanceFactory factory =
       SpiderInstanceFactoryImp.usingDependencyProvider(new DependencyProviderForTest());
   SpiderInstanceProvider.setSpiderInstanceFactory(factory);
   UriInfo uriInfo = new TestUri();
   recordEndpoint = new RecordEndpoint(uriInfo);
 }
Esempio n. 3
0
  @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);
  }
Esempio n. 4
0
  @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);
  }
Esempio n. 5
0
 private SpiderInstanceFactorySpy setupInstanceProviderWithFactorySpy() {
   SpiderInstanceFactorySpy factorySpy = new SpiderInstanceFactorySpy();
   SpiderInstanceProvider.setSpiderInstanceFactory(factorySpy);
   return factorySpy;
 }
Esempio n. 6
0
 private void setNotAuthorized() {
   SpiderInstanceFactory factory =
       SpiderInstanceFactoryImp.usingDependencyProvider(
           new DependencyProviderForTestNotAuthorized());
   SpiderInstanceProvider.setSpiderInstanceFactory(factory);
 }