Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjing2 committed Sep 12, 2024
1 parent 8adac82 commit 00eb983
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
*/
package com.alipay.sofa.ark.springboot.web;

import com.alipay.sofa.ark.api.ArkClient;
import com.alipay.sofa.ark.container.model.BizModel;
import com.alipay.sofa.ark.container.service.biz.BizManagerServiceImpl;
import com.alipay.sofa.ark.spi.registry.ServiceReference;
import com.alipay.sofa.ark.spi.service.ArkInject;
import com.alipay.sofa.ark.spi.service.registry.RegistryService;
import com.alipay.sofa.ark.spi.web.EmbeddedServerService;
import com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory.StaticResourceConfigurer;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
Expand Down Expand Up @@ -63,37 +58,10 @@ public void tearDown() {
currentThread().setContextClassLoader(currentThreadContextClassLoader);
}

private static class RegistryServiceHolder {
@ArkInject
private RegistryService registryService;

public RegistryService getRegistryService() {
return registryService;
}

}

@Test
public void testGetWebServerWithEmbeddedServerServiceNull() {
ServiceReference<EmbeddedServerService> reference = null;
RegistryServiceHolder holder = null;
if (ArkClient.getInjectionService() != null) {
holder = new RegistryServiceHolder();
ArkClient.getInjectionService().inject(holder);
if (holder.getRegistryService() != null) {
ServiceReference<EmbeddedServerService> ref = holder.getRegistryService().referenceService(EmbeddedServerService.class);
holder.getRegistryService().unPublishServices(svc -> svc == ref);
reference = ref;
}
}
try {
assertEquals(TomcatWebServer.class, arkTomcatServletWebServerFactory.getWebServer()
.getClass());
} finally {
if (reference != null) {
holder.getRegistryService().publishService(EmbeddedServerService.class, reference.getService(), reference.getServiceMetadata().getUniqueId(), reference.getServiceMetadata().getServiceProvider());
}
}
assertEquals(TomcatWebServer.class,
arkTomcatServletWebServerFactory.getWebServer().getClass());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.sofa.ark.springboot.web;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;

import static java.lang.Thread.currentThread;
import static org.junit.Assert.assertEquals;

public class ArkTomcatTest {

private ArkTomcatServletWebServerFactory arkTomcatServletWebServerFactory = new ArkTomcatServletWebServerFactory();

private ClassLoader currentThreadContextClassLoader;

@Before
public void setUp() {
currentThreadContextClassLoader = currentThread().getContextClassLoader();
}

@After
public void tearDown() {
currentThread().setContextClassLoader(currentThreadContextClassLoader);
}

@Test
public void testGetWebServerWithEmbeddedServerServiceNull() {
assertEquals(TomcatWebServer.class, arkTomcatServletWebServerFactory.getWebServer()
.getClass());
}
}

0 comments on commit 00eb983

Please sign in to comment.