Esempio n. 1
0
  @Before
  public void beforeTest() throws IOException, DeltaCalculatorException, ControlServiceException {
    String dataSchema =
        OperationsServiceIT.getResourceAsString(OperationsServiceIT.DATA_SCHEMA_LOCATION);
    PROFILE_BYTES = avroConverter.encode(ENDPOINT_PROFILE);
    PROFILE_JSON = avroConverter.encodeToJson(ENDPOINT_PROFILE);

    tenant = new TenantDto();
    tenant.setName(CUSTOMER_ID);
    tenant = userService.saveTenant(tenant);
    assertNotNull(tenant);
    assertNotNull(tenant.getId());

    ApplicationDto applicationDto = new ApplicationDto();
    applicationDto.setTenantId(tenant.getId());
    applicationDto.setApplicationToken(APPLICATION_ID);
    applicationDto.setName(APPLICATION_NAME);
    applicationDto.setSequenceNumber(NEW_APPLICATION_SEQ_NUMBER);
    applicationDto = applicationService.saveApp(applicationDto);
    APP_TOKEN = applicationDto.getApplicationToken();
    assertNotNull(applicationDto);
    assertNotNull(applicationDto.getId());

    application = applicationService.findAppById(applicationDto.getId());

    EndpointGroupDto groupAll =
        endpointService.findEndpointGroupsByAppId(application.getId()).get(0);

    CTLSchemaDto profileCtlSchema = new CTLSchemaDto();
    CtlSchemaMetaInfoDto metaInfo =
        new CtlSchemaMetaInfoDto(
            BasicEndpointProfile.SCHEMA$.getFullName(),
            application.getTenantId(),
            application.getId());
    profileCtlSchema.setMetaInfo(metaInfo);
    profileCtlSchema.setBody(BasicEndpointProfile.SCHEMA$.toString());
    profileCtlSchema.setVersion(1);
    profileCtlSchema.setDependencySet(new HashSet<CTLSchemaDto>());
    profileCtlSchema = ctlService.saveCtlSchema(profileCtlSchema);

    Schema schema = new Schema.Parser().parse(dataSchema);
    CTLSchemaDto confCtlSchema = new CTLSchemaDto();
    CtlSchemaMetaInfoDto confMetaInfo =
        new CtlSchemaMetaInfoDto(
            schema.getFullName(), application.getTenantId(), application.getId());
    confCtlSchema.setMetaInfo(confMetaInfo);
    confCtlSchema.setBody(schema.toString());
    confCtlSchema.setVersion(CONF_SCHEMA_VERSION);
    confCtlSchema.setDependencySet(new HashSet<CTLSchemaDto>());
    confCtlSchema = ctlService.saveCtlSchema(confCtlSchema);

    EndpointProfileSchemaDto profileSchemaObj = new EndpointProfileSchemaDto();
    profileSchemaObj.setVersion(PROFILE_SCHEMA_VERSION);
    profileSchemaObj.setCtlSchemaId(profileCtlSchema.getId());
    profileSchemaObj.setApplicationId(application.getId());
    EndpointProfileSchemaDto profileSchemaDto = profileService.saveProfileSchema(profileSchemaObj);

    profileSchema = profileService.findProfileSchemaById(profileSchemaDto.getId());

    EndpointGroupDto endpointGroup = new EndpointGroupDto();
    endpointGroup.setApplicationId(application.getId());
    endpointGroup.setName("Test group");
    endpointGroup.setWeight(277);
    endpointGroup.setDescription("Test Description");
    endpointGroup = endpointService.saveEndpointGroup(endpointGroup);

    ProfileFilterDto profileFilterObj = new ProfileFilterDto();
    profileFilterObj.setApplicationId(application.getId());
    profileFilterObj.setEndpointGroupId(endpointGroup.getId());
    profileFilterObj.setBody("profileBody.contains(\"dummy\")");
    profileFilterObj.setEndpointProfileSchemaId(profileSchema.getId());
    profileFilter = profileService.saveProfileFilter(profileFilterObj);
    profileService.activateProfileFilter(profileFilter.getId(), null);

    confSchema = new ConfigurationSchemaDto();
    confSchema.setApplicationId(application.getId());
    confSchema.setVersion(CONF_SCHEMA_VERSION);
    confSchema.setCtlSchemaId(confCtlSchema.getId());

    try {
      confSchema = configurationService.saveConfSchema(confSchema);
    } catch (IncorrectParameterException e) {
      Assert.fail("Can't generate schemas");
    }
    Assert.assertNotNull(confSchema);
    Assert.assertNotNull(confSchema.getId());

    egAllId = groupAll.getId();
    pfAllId = profileFilter.getId();
    ConfigurationDto confDto =
        configurationService.findConfigurationByEndpointGroupIdAndVersion(
            egAllId, CONF_SCHEMA_VERSION);
    cfAllId = confDto.getId();

    endpointConfiguration = new EndpointConfigurationDto();
    endpointConfiguration.setConfiguration(confDto.getBody().getBytes(UTF_8));
    endpointConfiguration.setConfigurationHash(
        EndpointObjectHash.fromSha1(confDto.getBody()).getData());
    endpointConfiguration = endpointService.saveEndpointConfiguration(endpointConfiguration);
    assertNotNull(endpointConfiguration);

    EndpointGroupStateDto egs = new EndpointGroupStateDto();
    egs.setConfigurationId(cfAllId);
    egs.setEndpointGroupId(egAllId);
    egs.setProfileFilterId(pfAllId);

    endpointProfile = new EndpointProfileDto();
    endpointProfile.setApplicationId(application.getId());
    endpointProfile.setEndpointKeyHash(Base64Utils.decodeFromString("EndpointId"));
    endpointProfile.setClientProfileBody(PROFILE_JSON);
    endpointProfile.setProfileHash(EndpointObjectHash.fromSha1(PROFILE_BYTES).getData());
    endpointProfile.setConfigurationHash(endpointConfiguration.getConfigurationHash());
    endpointProfile.setConfigurationVersion(CONF_SCHEMA_VERSION);
    endpointProfile.setClientProfileVersion(PROFILE_VERSION);
    endpointProfile.setGroupState(Collections.singletonList(egs));
    endpointProfile = endpointService.saveEndpointProfile(endpointProfile);
    assertNotNull(endpointProfile);
    assertNotNull(endpointProfile.getId());
  }
Esempio n. 2
0
  @Before
  public void beforeTest() throws IOException, SQLException {
    clearDBData();
    tenant = new TenantDto();
    tenant.setName(CUSTOMER_NAME);
    tenant = userService.saveTenant(tenant);

    application = new ApplicationDto();
    application.setName(APP_NAME);
    application.setTenantId(tenant.getId());
    application = applicationService.saveApp(application);

    CtlSchemaMetaInfoDto ctl1MetaDataDto =
        new CtlSchemaMetaInfoDto(EmptyData.SCHEMA$.getFullName(), null, null);
    CTLSchemaDto ctl1SchemaDto = new CTLSchemaDto();
    ctl1SchemaDto.setMetaInfo(ctl1MetaDataDto);
    ctl1SchemaDto.setVersion(2);
    ctl1SchemaDto.setBody(EmptyData.SCHEMA$.toString());
    ctl1SchemaDto = ctlService.saveCtlSchema(ctl1SchemaDto);

    schema1Dto = new EndpointProfileSchemaDto();
    schema1Dto.setVersion(PROFILE_SCHEMA_VERSION);
    schema1Dto.setCtlSchemaId(ctl1SchemaDto.getId());
    schema1Dto.setApplicationId(application.getId());
    schema1Dto = daoProfileService.saveProfileSchema(schema1Dto);

    CtlSchemaMetaInfoDto ctl2MetaDataDto =
        new CtlSchemaMetaInfoDto(
            BasicEndpointProfile.SCHEMA$.getFullName(),
            application.getTenantId(),
            application.getId());
    CTLSchemaDto ctl2SchemaDto = new CTLSchemaDto();
    ctl2SchemaDto.setMetaInfo(ctl2MetaDataDto);
    ctl2SchemaDto.setVersion(2);
    ctl2SchemaDto.setBody(BasicEndpointProfile.SCHEMA$.toString());
    ctl2SchemaDto = ctlService.saveCtlSchema(ctl2SchemaDto);

    schema2Dto = new EndpointProfileSchemaDto();
    schema2Dto.setVersion(NEW_PROFILE_SCHEMA_VERSION);
    schema2Dto.setCtlSchemaId(ctl2SchemaDto.getId());
    schema2Dto.setApplicationId(application.getId());
    schema2Dto = daoProfileService.saveProfileSchema(schema2Dto);

    SdkProfileDto sdkPropertiesDto = new SdkProfileDto();
    sdkPropertiesDto.setApplicationId(application.getId());
    sdkPropertiesDto.setProfileSchemaVersion(PROFILE_SCHEMA_VERSION);
    sdkPropertiesDto.setConfigurationSchemaVersion(1);
    sdkPropertiesDto.setNotificationSchemaVersion(1);
    sdkPropertiesDto.setLogSchemaVersion(1);
    sdkPropertiesDto.setApplicationToken(application.getApplicationToken());
    sdkPropertiesDto = sdkProfileService.saveSdkProfile(sdkPropertiesDto);
    sdkToken = new SdkProfile(sdkPropertiesDto).getToken();

    SdkProfileDto newSdkProfileDto = new SdkProfileDto();
    newSdkProfileDto.setApplicationId(application.getId());
    newSdkProfileDto.setProfileSchemaVersion(NEW_PROFILE_SCHEMA_VERSION);
    newSdkProfileDto.setConfigurationSchemaVersion(1);
    newSdkProfileDto.setNotificationSchemaVersion(1);
    newSdkProfileDto.setLogSchemaVersion(1);
    newSdkProfileDto.setApplicationToken(application.getApplicationToken());
    newSdkProfileDto = sdkProfileService.saveSdkProfile(newSdkProfileDto);
    newSdkToken = new SdkProfile(newSdkProfileDto).getToken();
  }