Commit c1c95fbb authored by Sanjeev-SLB's avatar Sanjeev-SLB
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://community.opengroup.org/osdu/platform/system/notification into broken-pipe-fix
parents b0f79e2b 2f877c80
Pipeline #70553 failed with stages
in 36 minutes and 52 seconds
package org.opengroup.osdu.notification.provider.azure.di;
import lombok.Data;
import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig;
import org.opengroup.osdu.notification.provider.interfaces.IAppProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties
public class SubscriptionAPIConfigBean extends AbstractFactoryBean<SubscriptionAPIConfig> {
@Autowired
private IAppProperties config;
private String apiKey;
@Override
public Class<?> getObjectType() {
return SubscriptionAPIConfig.class;
}
@Override
protected SubscriptionAPIConfig createInstance() throws Exception {
return SubscriptionAPIConfig
.builder()
.rootUrl(config.getRegisterAPI())
.apiKey(apiKey)
.build();
}
}
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.notification.provider.azure.di;
import org.opengroup.osdu.core.common.http.IHttpClient;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.notification.ISubscriptionFactory;
import org.opengroup.osdu.core.common.notification.ISubscriptionService;
import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig;
import org.opengroup.osdu.core.common.notification.SubscriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component
@Primary
public class SubscriptionFactoryAzure implements ISubscriptionFactory {
private final SubscriptionAPIConfig config;
private final IHttpClient client;
@Autowired
public SubscriptionFactoryAzure(final SubscriptionAPIConfig subscriptionConfig, final IHttpClient httpClient) {
Objects.requireNonNull(subscriptionConfig, "SubscriptionAPIConfig cannot be null");
this.config = subscriptionConfig;
this.client = httpClient;
}
@Override
public ISubscriptionService create(final DpsHeaders dpsHeaders) {
Objects.requireNonNull(dpsHeaders, "headers cannot be null");
return new SubscriptionService(this.config, this.client, dpsHeaders);
}
}
package org.opengroup.osdu.notification.di;
import org.junit.Assert;
import org.junit.Test;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.notification.ISubscriptionService;
import org.opengroup.osdu.core.common.notification.SubscriptionAPIConfig;
import org.opengroup.osdu.notification.provider.azure.di.SubscriptionFactoryAzure;
public class SubscriptionFactoryAzureTest {
@Test
public void constructor_should_work_when_config_is_not_null() {
SubscriptionAPIConfig subscriptionAPIConfig = SubscriptionAPIConfig.builder().build();
subscriptionAPIConfig.setApiKey("apiKey");
subscriptionAPIConfig.setRootUrl("rootUrl");
SubscriptionFactoryAzure subscriptionFactoryAzure = new SubscriptionFactoryAzure(subscriptionAPIConfig, null);
Assert.assertNotNull(subscriptionFactoryAzure);
}
@Test(expected = NullPointerException.class)
public void constructor_should_throw_npe_if_config_is_null() {
SubscriptionFactoryAzure subscriptionFactoryAzure = new SubscriptionFactoryAzure(null, null);
}
@Test
public void create_subscriptionService_instance_dpsHeaders_is_not_null() {
DpsHeaders dpsHeaders = new DpsHeaders();
SubscriptionAPIConfig subscriptionAPIConfig = SubscriptionAPIConfig.builder().build();
subscriptionAPIConfig.setApiKey("apiKey");
subscriptionAPIConfig.setRootUrl("rootUrl");
SubscriptionFactoryAzure subscriptionFactoryAzure = new SubscriptionFactoryAzure(subscriptionAPIConfig, null);
ISubscriptionService subscriptionService = subscriptionFactoryAzure.create(dpsHeaders);
Assert.assertNotNull(subscriptionService);
}
@Test(expected = NullPointerException.class)
public void create_subscriptionService_should_throw_npe_if_headers_is_null() {
SubscriptionAPIConfig subscriptionAPIConfig = SubscriptionAPIConfig.builder().build();
subscriptionAPIConfig.setApiKey("apiKey");
subscriptionAPIConfig.setRootUrl("rootUrl");
SubscriptionFactoryAzure subscriptionFactoryAzure = new SubscriptionFactoryAzure(subscriptionAPIConfig, null);
ISubscriptionService subscriptionService = subscriptionFactoryAzure.create(null);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment