Search in sources :

Example 11 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.

the class TestCseClientHttpRequest method testNormal.

@Test
public void testNormal() throws IOException {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    UnitTestMeta meta = new UnitTestMeta();
    CseContext.getInstance().getSchemaListenerManager().setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(SpringmvcImpl.class);
    CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);
    Holder<Invocation> holder = new Holder<>();
    CseClientHttpRequest client = new CseClientHttpRequest(URI.create("cse://app:test/" + SpringmvcImpl.class.getSimpleName() + "/bytes"), HttpMethod.POST) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected Response doInvoke(Invocation invocation) {
            holder.value = invocation;
            return Response.ok("result");
        }
    };
    byte[] body = "abc".getBytes();
    client.setRequestBody(body);
    client.execute();
    Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
}
Also used : RestEngineSchemaListener(org.apache.servicecomb.common.rest.RestEngineSchemaListener) UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) Invocation(org.apache.servicecomb.core.Invocation) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Holder(javax.xml.ws.Holder) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Example 12 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.

the class MockUtil method mockMicroserviceMeta.

public void mockMicroserviceMeta() {
    new MockUp<MicroserviceMeta>() {

        @Mock
        public SchemaMeta ensureFindSchemaMeta(String schemaId) {
            SchemaMeta lSchemaMeta = Mockito.mock(SchemaMeta.class);
            Mockito.when(lSchemaMeta.getSwaggerIntf()).thenAnswer(new Answer<Class<? extends TestPojoConsumerProvider>>() {

                @Override
                public Class<? extends TestPojoConsumerProvider> answer(InvocationOnMock invocation) throws Throwable {
                    return TestPojoConsumerProvider.class;
                }
            });
            return lSchemaMeta;
        }

        @Mock
        public SchemaMeta ensureFindSchemaMeta(Class<?> schemaIntf) {
            return Mockito.mock(SchemaMeta.class);
        }
    };
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MockUp(mockit.MockUp) TestPojoConsumerProvider(org.apache.servicecomb.provider.pojo.TestPojoConsumerProvider)

Example 13 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class UrlPathItemTest method initStrBuilder.

@Before
public void initStrBuilder() {
    accessLogEvent = new ServerAccessLogEvent();
    routingContext = Mockito.mock(RoutingContext.class);
    finishEvent = Mockito.mock(InvocationFinishEvent.class);
    invocation = Mockito.mock(Invocation.class);
    serverRequest = Mockito.mock(HttpServerRequest.class);
    operationMeta = Mockito.mock(OperationMeta.class);
    schemaMeta = Mockito.mock(SchemaMeta.class);
    swagger = Mockito.mock(Swagger.class);
    restClientRequest = Mockito.mock(RestClientRequestImpl.class);
    clientRequest = Mockito.mock(HttpClientRequest.class);
    accessLogEvent.setRoutingContext(routingContext);
    strBuilder = new StringBuilder();
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent) InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) Invocation(org.apache.servicecomb.core.Invocation) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) RestClientRequestImpl(org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Before(org.junit.Before)

Example 14 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class ProducerTestsAfterBootup method testSchemaNotChange.

public void testSchemaNotChange(SCBEngine scbEngine) {
    LOGGER.info("ProducerTestsAfterBootup testing start");
    // we can not set microserviceName any more
    SchemaMeta meta = scbEngine.getProducerProviderManager().registerSchema("test1", new CodeFirstSpringmvcForSchema());
    String codeFirst = getSwaggerContent(meta.getSwagger());
    TestMgr.check(EXPECTED_DATA, codeFirst);
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta)

Example 15 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class TestInspectorBootListener method enabled.

@Test
public void enabled() {
    Holder<Object> holder = new Holder<>();
    SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
    scbEngine.setProducerMicroserviceMeta(new MicroserviceMeta(scbEngine, "ms", false));
    scbEngine.setProducerProviderManager(new ProducerProviderManager(scbEngine) {

        @Override
        public SchemaMeta registerSchema(String schemaId, Object instance) {
            if ("inspector".equals(schemaId)) {
                holder.value = instance;
            }
            return null;
        }
    });
    InspectorConfig inspectorConfig = new InspectorConfig().setEnabled(true);
    new InspectorBootListener(inspectorConfig, null).onAfterTransport(new BootEvent(scbEngine, EventType.AFTER_TRANSPORT));
    Assert.assertNotNull(holder.value);
}
Also used : SCBEngine(org.apache.servicecomb.core.SCBEngine) Holder(org.apache.servicecomb.foundation.common.Holder) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) ProducerProviderManager(org.apache.servicecomb.core.provider.producer.ProducerProviderManager) Test(org.junit.Test)

Aggregations

SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)58 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)28 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)25 Test (org.junit.Test)24 Invocation (org.apache.servicecomb.core.Invocation)13 Swagger (io.swagger.models.Swagger)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 Executor (java.util.concurrent.Executor)5 InvocationRuntimeType (org.apache.servicecomb.core.definition.InvocationRuntimeType)5 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)5 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)5 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)5 MockUp (mockit.MockUp)4 NonSwaggerInvocation (org.apache.servicecomb.core.NonSwaggerInvocation)4 Transport (org.apache.servicecomb.core.Transport)4 TransportManager (org.apache.servicecomb.core.transport.TransportManager)4 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)4 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)4 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)4