Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Jun 27, 2016
1 parent 9b49458 commit 3bcc43e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 45 deletions.
Expand Up @@ -226,7 +226,7 @@ public void deleteApplication(String applicationId) throws Exception {
restTemplate.postForLocation(restTemplate.getUrl() + "delApplication", params);
}

public ConfigurationSchemaDto editConfigurationSchema(ConfigurationSchemaDto configurationSchema) throws Exception {
public ConfigurationSchemaDto saveConfigurationSchema(ConfigurationSchemaDto configurationSchema) throws Exception {
return restTemplate.postForObject(restTemplate.getUrl() + "saveConfigurationSchema", configurationSchema, ConfigurationSchemaDto.class);
}

Expand Down
Expand Up @@ -534,7 +534,7 @@ public ConfigurationSchemaDto getConfigurationSchema(String configurationSchemaI
* (non-Javadoc)
*
* @see org.kaaproject.kaa.server.control.service.ControlService#
* editConfigurationSchema
* saveConfigurationSchema
* (org.kaaproject.kaa.common.dto.ConfigurationSchemaDto)
*/
@Override
Expand Down
Expand Up @@ -81,7 +81,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.ResourceAccessException;

import javax.sql.DataSource;
import java.io.BufferedReader;
Expand Down Expand Up @@ -635,17 +634,18 @@ protected ApplicationDto createApplication(TenantUserDto tenant) throws Exceptio
* @throws Exception the exception
*/
protected ConfigurationSchemaDto createConfigurationSchema() throws Exception {
return createConfigurationSchema(null);
return createConfigurationSchema(null, null);
}

/**
* Creates the configuration schema.
*
* @param applicationId the application id
* @param ctlSchemaId
* @return the configuration schema dto
* @throws Exception the exception
*/
protected ConfigurationSchemaDto createConfigurationSchema(String applicationId) throws Exception {
protected ConfigurationSchemaDto createConfigurationSchema(String applicationId, String ctlSchemaId) throws Exception {
ConfigurationSchemaDto configurationSchema = new ConfigurationSchemaDto();
configurationSchema.setStatus(UpdateStatus.ACTIVE);
configurationSchema.setName(generateString("Test Schema"));
Expand All @@ -657,10 +657,17 @@ protected ConfigurationSchemaDto createConfigurationSchema(String applicationId)
else {
configurationSchema.setApplicationId(applicationId);
}

if (strIsEmpty(ctlSchemaId)) {
CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null);
configurationSchema.setCtlSchemaId(ctlSchema.getId());
} else {
configurationSchema.setCtlSchemaId(ctlSchemaId);
}

loginTenantDeveloper(tenantDeveloperDto.getUsername());
// ConfigurationSchemaDto savedConfigurationSchema = client.createConfigurationSchema(configurationSchema, TEST_CONFIG_SCHEMA); //TODO refactor
// return savedConfigurationSchema;
return null;
ConfigurationSchemaDto savedConfigurationSchema = client.saveConfigurationSchema(configurationSchema);
return savedConfigurationSchema;
}

/**
Expand Down Expand Up @@ -888,7 +895,7 @@ protected ConfigurationDto createConfiguration(String configurationSchemaId, Str

ConfigurationSchemaDto configSchema = null;
if (strIsEmpty(configurationSchemaId)) {
configSchema = createConfigurationSchema(applicationId);
configSchema = createConfigurationSchema(applicationId, null);
configuration.setSchemaId(configSchema.getId());
} else {
loginTenantDeveloper(tenantDeveloperDto.getUsername());
Expand Down
Expand Up @@ -147,9 +147,9 @@ public void testDeleteConfigurationRecord() throws Exception {
public void testGetVacantSchemasByEndpointGroupId() throws Exception {

EndpointGroupDto endpointGroup = createEndpointGroup();
ConfigurationSchemaDto configurationSchema1 = createConfigurationSchema(endpointGroup.getApplicationId());
ConfigurationSchemaDto configurationSchema2 = createConfigurationSchema(endpointGroup.getApplicationId());
ConfigurationSchemaDto configurationSchema3 = createConfigurationSchema(endpointGroup.getApplicationId());
ConfigurationSchemaDto configurationSchema1 = createConfigurationSchema(endpointGroup.getApplicationId(), null);
ConfigurationSchemaDto configurationSchema2 = createConfigurationSchema(endpointGroup.getApplicationId(), null);
ConfigurationSchemaDto configurationSchema3 = createConfigurationSchema(endpointGroup.getApplicationId(), null);

createConfiguration(configurationSchema1.getId(), endpointGroup.getId());
createConfiguration(configurationSchema2.getId(), endpointGroup.getId());
Expand Down
Expand Up @@ -16,17 +16,20 @@

package org.kaaproject.kaa.server.control;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import org.kaaproject.kaa.common.dto.ApplicationDto;
import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto;
import org.kaaproject.kaa.common.dto.UpdateStatus;
import org.kaaproject.kaa.common.dto.VersionDto;
import org.kaaproject.kaa.common.dto.admin.SchemaVersions;
import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto;

/**
* The Class ControlServerConfigurationSchemaIT.
Expand All @@ -45,27 +48,6 @@ public void testCreateConfigurationSchema() throws Exception {
Assert.assertFalse(configurationSchema.getProtocolSchema().isEmpty());
}

/**
* Test create invalid configuration schema.
*
* @throws Exception the exception
*/
@Test
public void testCreateInvalidConfigurationSchema() throws Exception {
final ConfigurationSchemaDto configurationSchema = new ConfigurationSchemaDto();
configurationSchema.setStatus(UpdateStatus.ACTIVE);
ApplicationDto application = createApplication(tenantAdminDto);
configurationSchema.setApplicationId(application.getId());
loginTenantDeveloper(tenantDeveloperDto.getUsername());
checkBadRequest(new TestRestCall() {
@Override
public void executeRestCall() throws Exception {
// client.createConfigurationSchema(configurationSchema, TEST_INVALID_CONFIG_SCHEMA);//TODO refactor

}
});
}

/**
* Test get configuration schema.
*
Expand Down Expand Up @@ -98,7 +80,7 @@ public void testGetConfigurationSchemasByApplicationToken() throws Exception {
configurationSchemas.addAll(defaultConfigurationSchemas);

for (int i=0;i<10;i++) {
ConfigurationSchemaDto configurationSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configurationSchema = createConfigurationSchema(application.getId(), null);
configurationSchemas.add(configurationSchema);
}

Expand Down Expand Up @@ -135,7 +117,7 @@ public void testGetConfigurationSchemaVersionsByApplicationToken() throws Except
configurationSchemas.addAll(defaultConfigurationSchemas);

for (int i=0;i<10;i++) {
ConfigurationSchemaDto configurationSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configurationSchema = createConfigurationSchema(application.getId(), null);
configurationSchemas.add(configurationSchema);
}

Expand Down Expand Up @@ -168,7 +150,7 @@ public void testUpdateConfigurationSchema() throws Exception {
configurationSchema.setDescription(generateString("Test Desc 2"));

ConfigurationSchemaDto updatedConfigurationSchema = client
.editConfigurationSchema(configurationSchema);
.saveConfigurationSchema(configurationSchema);

Assert.assertTrue(updatedConfigurationSchema.equals(configurationSchema));
}
Expand Down
Expand Up @@ -45,7 +45,7 @@ public class ControlServerSdkIT extends AbstractTestControlServer {
public void testGenerateJavaSdk() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());
LogSchemaDto logSchema = createLogSchema(application.getId());

Expand All @@ -67,7 +67,7 @@ public void testGenerateJavaSdk() throws Exception {
public void testGenerateJavaSdkWithEventSupport() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());

LogSchemaDto logSchema = createLogSchema(application.getId());
Expand All @@ -93,7 +93,7 @@ public void testGenerateJavaSdkWithEventSupport() throws Exception {
public void testGenerateAndroidSdkWithEventSupport() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());
LogSchemaDto logSchema = createLogSchema(application.getId());

Expand All @@ -119,7 +119,7 @@ public void testGenerateAndroidSdkWithEventSupport() throws Exception {
public void testGenerateCppSdk() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());
LogSchemaDto logSchema = createLogSchema(application.getId());

Expand All @@ -141,7 +141,7 @@ public void testGenerateCppSdk() throws Exception {
public void testGenerateCppSdkWithEventSupport() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());
LogSchemaDto logSchema = createLogSchema(application.getId());

Expand All @@ -167,7 +167,7 @@ public void testGenerateCppSdkWithEventSupport() throws Exception {
public void testGenerateCSdk() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());
LogSchemaDto logSchema = createLogSchema(application.getId());

Expand All @@ -192,7 +192,7 @@ public void testGenerateCSdk() throws Exception {
public void testGenerateCSdkWithEventSupport() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
NotificationSchemaDto notificationSchema = createUserNotificationSchema(application.getId());
LogSchemaDto logSchema = createLogSchema(application.getId());

Expand Down Expand Up @@ -270,7 +270,7 @@ public void testGenerateJavaSdkWithInvalidNotificationSchema() throws Exception
final ApplicationDto application = createApplication(tenantAdminDto);
loginTenantDeveloper(tenantDeveloperUser);
final EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), null);
final ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId());
final ConfigurationSchemaDto configSchema = createConfigurationSchema(application.getId(), null);
checkNotFound(new TestRestCall() {
@Override
public void executeRestCall() throws Exception {
Expand Down
Expand Up @@ -253,7 +253,7 @@ public void beforeTest() throws IOException, NoSuchAlgorithmException, SQLExcept
confSchema = new ConfigurationSchema();
confSchema.setApplication(application);
confSchema.setVersion(CONF_SCHEMA_VERSION);
// confSchema.setSchema(dataSchema);//TODO refactor
confSchema.setCtlSchema(ctlSchema);
try {
confSchema = new ConfigurationSchema(configurationService.saveConfSchema(confSchema.toDto()));
} catch (IncorrectParameterException e) {
Expand Down

0 comments on commit 3bcc43e

Please sign in to comment.