Search in sources :

Example 6 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfBlackByServiceName.

@Test
public void testIsValidOfBlackByServiceName() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust*");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    service.setServiceName("trustCustomer");
    Assert.assertTrue(!controller.isAllowed(service));
    service.setServiceName("nottrustCustomer");
    Assert.assertTrue(controller.isAllowed(service));
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*trust");
    service.setServiceName("Customer_trust");
    Assert.assertTrue(!controller.isAllowed(service));
    service.setServiceName("Customer_trust_not");
    Assert.assertTrue(controller.isAllowed(service));
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust");
    service.setServiceName("trust");
    Assert.assertTrue(!controller.isAllowed(service));
    service.setServiceName("Customer_trust");
    Assert.assertTrue(controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 7 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestAccessController method testIsValidOfWhiteByProperties.

@Test
public void testIsValidOfWhiteByProperties() {
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "tag");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
    ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "test");
    AccessController controller = new AccessController();
    Microservice service = new Microservice();
    Map<String, String> map = new HashMap<>();
    map.put("tag", "test");
    service.setProperties(map);
    Assert.assertTrue(controller.isAllowed(service));
    map.put("tag", "testa");
    service.setProperties(map);
    Assert.assertTrue(!controller.isAllowed(service));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class MicroserviceRegisterTask method checkSchemaIdSet.

private boolean checkSchemaIdSet() {
    Microservice existMicroservice = srClient.getMicroservice(microservice.getServiceId());
    if (existMicroservice == null) {
        LOGGER.error("Error to get microservice from service center when check schema set");
        return false;
    }
    Set<String> existSchemas = new HashSet<>(existMicroservice.getSchemas());
    Set<String> localSchemas = new HashSet<>(microservice.getSchemas());
    schemaIdSetMatch = existSchemas.equals(localSchemas);
    if (!schemaIdSetMatch) {
        LOGGER.warn("SchemaIds is different between local and service center. " + "serviceId=[{}] appId=[{}], name=[{}], version=[{}], env=[{}], local schemaIds={}, service center schemaIds={}", microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment(), localSchemas, existSchemas);
        // because even schema ids not same, will also check content to see if should fail.
        return true;
    }
    LOGGER.info("SchemaIds are equals to service center. serviceId=[{}], appId=[{}], name=[{}], version=[{}], env=[{}], schemaIds={}", microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment(), localSchemas);
    return true;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashSet(java.util.HashSet)

Example 9 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestMicroserviceFactory method testSetDescription.

@Test
public void testSetDescription() {
    MicroserviceFactory factory = new MicroserviceFactory();
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { "test1", "test2" });
    Microservice microservice = factory.create(configuration);
    Assert.assertEquals("test1,test2", microservice.getDescription());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Configuration(org.apache.commons.configuration.Configuration) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Example 10 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestMicroserviceFactory method testSetDescriptionOnBlankDescription.

@Test
public void testSetDescriptionOnBlankDescription() {
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { " ", " " });
    MicroserviceFactory factory = new MicroserviceFactory();
    Microservice microservice = factory.create(configuration);
    Assert.assertEquals(" , ", microservice.getDescription());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Configuration(org.apache.commons.configuration.Configuration) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3