Search in sources :

Example 1 with HasNewSecretResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementServiceTest method testHasNewSecretAuthenticationKey.

@Test
public void testHasNewSecretAuthenticationKey() {
    final HasNewSecretResponse responseTrue = new HasNewSecretResponse();
    responseTrue.setHasNewSecret(true);
    final HasNewSecretResponse responseFalse = new HasNewSecretResponse();
    responseFalse.setHasNewSecret(false);
    when(this.secretManagementClient.hasNewSecretRequest(same(messageMetadata), any())).thenAnswer(invocationOnMock -> {
        if (((HasNewSecretRequest) invocationOnMock.getArgument(1)).getSecretType().equals(SecretType.E_METER_AUTHENTICATION_KEY)) {
            return responseTrue;
        } else {
            return responseFalse;
        }
    });
    // EXECUTE
    final boolean result = this.secretManagementTestService.hasNewSecret(messageMetadata, DEVICE_IDENTIFICATION);
    // ASSERT
    assertThat(result).isTrue();
}
Also used : HasNewSecretResponse(org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse) Test(org.junit.jupiter.api.Test)

Example 2 with HasNewSecretResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementEndpoint method hasNewSecret.

public HasNewSecretResponse hasNewSecret(final HasNewSecretRequest request) {
    final SecretType type = this.converter.convertToSecretType(request.getSecretType());
    final boolean result = this.secretManagementService.hasNewSecret(request.getDeviceId(), type);
    final HasNewSecretResponse response = new HasNewSecretResponse();
    response.setHasNewSecret(result);
    return response;
}
Also used : SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType) HasNewSecretResponse(org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse)

Example 3 with HasNewSecretResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementService method hasNewSecret.

public boolean hasNewSecret(final MessageMetadata messageMetadata, final String deviceIdentification) {
    final HasNewSecretRequest requestAKey = new HasNewSecretRequest();
    final HasNewSecretRequest requestEKey = new HasNewSecretRequest();
    requestAKey.setDeviceId(deviceIdentification);
    requestAKey.setSecretType(SecretType.E_METER_AUTHENTICATION_KEY);
    final HasNewSecretResponse responseAKey = this.secretManagementClient.hasNewSecretRequest(messageMetadata, requestAKey);
    requestEKey.setDeviceId(deviceIdentification);
    requestEKey.setSecretType(SecretType.E_METER_ENCRYPTION_KEY_UNICAST);
    final HasNewSecretResponse responseEKey = this.secretManagementClient.hasNewSecretRequest(messageMetadata, requestEKey);
    return responseAKey.isHasNewSecret() || responseEKey.isHasNewSecret();
}
Also used : HasNewSecretRequest(org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretRequest) HasNewSecretResponse(org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse)

Example 4 with HasNewSecretResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementServiceTest method testHasNewSecretEncryptionKey.

@Test
public void testHasNewSecretEncryptionKey() {
    final HasNewSecretResponse responseTrue = new HasNewSecretResponse();
    responseTrue.setHasNewSecret(true);
    final HasNewSecretResponse responseFalse = new HasNewSecretResponse();
    responseFalse.setHasNewSecret(false);
    when(this.secretManagementClient.hasNewSecretRequest(same(messageMetadata), any())).thenAnswer(invocationOnMock -> {
        if (((HasNewSecretRequest) invocationOnMock.getArgument(1)).getSecretType().equals(SecretType.E_METER_ENCRYPTION_KEY_UNICAST)) {
            return responseTrue;
        } else {
            return responseFalse;
        }
    });
    // EXECUTE
    final boolean result = this.secretManagementTestService.hasNewSecret(messageMetadata, DEVICE_IDENTIFICATION);
    // ASSERT
    assertThat(result).isTrue();
}
Also used : HasNewSecretResponse(org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HasNewSecretResponse (org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretResponse)4 Test (org.junit.jupiter.api.Test)2 SecretType (org.opensmartgridplatform.secretmanagement.application.domain.SecretType)1 HasNewSecretRequest (org.opensmartgridplatform.ws.schema.core.secret.management.HasNewSecretRequest)1