Skip to content

Commit

Permalink
refact to using junit5 and jdk17
Browse files Browse the repository at this point in the history
  • Loading branch information
significantfrank committed Apr 21, 2024
1 parent c9de978 commit 8ec1631
Show file tree
Hide file tree
Showing 43 changed files with 143 additions and 191 deletions.
5 changes: 0 additions & 5 deletions cola-components/cola-component-catchlog-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
<scope>provided</scope>
</dependency>

<!-- 日志包 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- cola组件依赖 -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import com.alibaba.cola.catchlog.CatchLogAspect;
import com.alibaba.cola.catchlog.CatchLogAutoConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {CatchLogAutoConfiguration.class, Demo.class, CatchLogAspect.class, Application.class})
public class CatchLogTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.alibaba.cola.domain;

import com.alibaba.cola.domain.Entity;
import jakarta.annotation.Resource;

import javax.annotation.Resource;

/**
* Customer
Expand Down
2 changes: 1 addition & 1 deletion cola-components/cola-component-extension-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
https://blog.csdn.net/significantfrank/article/details/100074716

## 使用介绍
参看测试代码`com.alibaba.cola.extension.test.ExtensionTest`
参看测试代码`com.alibaba.cola.extension.ExtensionTest`

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Repeatable(Extensions.class)
@Component
public @interface Extension {
String bizId() default BizScenario.DEFAULT_BIZ_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
package com.alibaba.cola.extension;

import com.alibaba.cola.extension.register.AbstractComponentExecutor;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
* ExtensionExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@

String[] scenario() default BizScenario.DEFAULT_SCENARIO;

Extension[] value() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import com.alibaba.cola.extension.Extension;
import com.alibaba.cola.extension.ExtensionPointI;
import com.alibaba.cola.extension.Extensions;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import java.util.Map;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
package com.alibaba.cola.extension.register;

import com.alibaba.cola.extension.*;
import jakarta.annotation.Resource;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
* ExtensionRegister
*
Expand Down Expand Up @@ -66,20 +65,8 @@ public void doRegistrationExtensions(ExtensionPointI extensionObject){
}

Extensions extensionsAnnotation = AnnotationUtils.findAnnotation(extensionClz, Extensions.class);
Extension[] extensions = extensionsAnnotation.value();
if (!ObjectUtils.isEmpty(extensions)){
for (Extension extensionAnn : extensions) {
BizScenario bizScenario = BizScenario.valueOf(extensionAnn.bizId(), extensionAnn.useCase(), extensionAnn.scenario());
ExtensionCoordinate extensionCoordinate = new ExtensionCoordinate(calculateExtensionPoint(extensionClz), bizScenario.getUniqueIdentity());
ExtensionPointI preVal = extensionRepository.getExtensionRepo().put(extensionCoordinate, extensionObject);
if (preVal != null) {
String errMessage = "Duplicate registration is not allowed for :" + extensionCoordinate;
throw new ExtensionException(EXTENSION_DEFINE_DUPLICATE, errMessage);
}
}
}

//
//Support multiple extensions registration
String[] bizIds = extensionsAnnotation.bizId();
String[] useCases = extensionsAnnotation.useCase();
String[] scenarios = extensionsAnnotation.scenario();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.alibaba.cola.extension.test;
package com.alibaba.cola.extension;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
* Application
Expand All @@ -10,6 +11,7 @@
* @date 2020-11-10 3:58 PM
*/
@SpringBootApplication
@ComponentScan(basePackages = "com.alibaba.cola")
public class Application {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package com.alibaba.cola.extension.test;
package com.alibaba.cola.extension;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.extension.BizScenario;
import com.alibaba.cola.extension.test.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.test.customer.client.Constants;
import com.alibaba.cola.extension.test.customer.client.CustomerDTO;
import com.alibaba.cola.extension.test.customer.client.CustomerServiceI;
import com.alibaba.cola.extension.test.customer.domain.CustomerType;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.alibaba.cola.extension.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.customer.client.Constants;
import com.alibaba.cola.extension.customer.client.CustomerDTO;
import com.alibaba.cola.extension.customer.client.CustomerServiceI;
import com.alibaba.cola.extension.customer.domain.CustomerType;
import jakarta.annotation.Resource;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;


/**
* ExtensionTest
*
* @author Frank Zhang
* @date 2020-11-14 2:55 PM
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class ExtensionTest {
@Resource
Expand All @@ -43,7 +41,7 @@ public void testBiz1UseCase1Scenario1AddCustomerSuccess(){
Response response = customerService.addCustomer(addCustomerCmd);

//3. Expect Success
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}

@Test
Expand All @@ -62,7 +60,7 @@ public void testBiz1UseCase1AddCustomerSuccess(){
Response response = customerService.addCustomer(addCustomerCmd);

//3. Expect Success
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}

@Test
Expand All @@ -81,6 +79,6 @@ public void testBiz1AddCustomerSuccess(){
Response response = customerService.addCustomer(addCustomerCmd);

//3. Expect Success
Assert.assertTrue(response.isSuccess());
Assertions.assertTrue(response.isSuccess());
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package com.alibaba.cola.extension.test;
package com.alibaba.cola.extension;

import com.alibaba.cola.extension.BizScenario;
import com.alibaba.cola.extension.ExtensionExecutor;
import com.alibaba.cola.extension.test.customer.app.extensionpoint.StatusNameConvertorExtPt;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.alibaba.cola.extension.customer.app.extensionpoint.StatusNameConvertorExtPt;

import jakarta.annotation.Resource;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
* 多坐标测试
*
* @author wangguoqiang wrote on 2022/10/10 14:54
* @version 1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class MultiCoordinateTests {

Expand Down Expand Up @@ -45,23 +41,13 @@ public void testMultiCoordinate() {
String name7 = extensionExecutor.execute(StatusNameConvertorExtPt.class, bizScenario7, pt -> pt.statusNameConvertor(7));
String name8 = extensionExecutor.execute(StatusNameConvertorExtPt.class, bizScenario8, pt -> pt.statusNameConvertor(8));

Assert.assertEquals("one",name1);
Assert.assertEquals("two",name2);
Assert.assertEquals("three",name3);
Assert.assertEquals("four",name4);
Assert.assertEquals("five",name5);
Assert.assertEquals("six",name6);
Assert.assertEquals("seven",name7);
Assert.assertEquals("eight",name8);
}

@Test
public void testMultiCoordinateWithAnnotation() {
BizScenario bizScenario1 = BizScenario.valueOf("Sony", "user", "scenario3");
BizScenario bizScenario2 = BizScenario.valueOf("Siemens", "order", "scenario1");
String name1 = extensionExecutor.execute(StatusNameConvertorExtPt.class, bizScenario1, pt -> pt.statusNameConvertor(1));
String name2 = extensionExecutor.execute(StatusNameConvertorExtPt.class, bizScenario2, pt -> pt.statusNameConvertor(2));
Assert.assertEquals("one",name1);
Assert.assertEquals("two",name2);
Assertions.assertEquals("one",name1);
Assertions.assertEquals("two",name2);
Assertions.assertEquals("three",name3);
Assertions.assertEquals("four",name4);
Assertions.assertEquals("five",name5);
Assertions.assertEquals("six",name6);
Assertions.assertEquals("seven",name7);
Assertions.assertEquals("eight",name8);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.alibaba.cola.extension.test.customer.app;
package com.alibaba.cola.extension.customer.app;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.extension.ExtensionExecutor;
import com.alibaba.cola.extension.test.customer.app.extensionpoint.CustomerConvertorExtPt;
import com.alibaba.cola.extension.test.customer.infrastructure.DomainEventPublisher;
import com.alibaba.cola.extension.test.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.test.customer.domain.CustomerEntity;
import com.alibaba.cola.extension.test.customer.app.extensionpoint.AddCustomerValidatorExtPt;
import com.alibaba.cola.extension.customer.app.extensionpoint.AddCustomerValidatorExtPt;
import com.alibaba.cola.extension.customer.app.extensionpoint.CustomerConvertorExtPt;
import com.alibaba.cola.extension.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.customer.domain.CustomerEntity;
import com.alibaba.cola.extension.customer.infrastructure.DomainEventPublisher;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
* AddCustomerCmdExe
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.alibaba.cola.extension.test.customer.app;
package com.alibaba.cola.extension.customer.app;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.extension.test.customer.client.CustomerCreatedEvent;
import com.alibaba.cola.extension.customer.client.CustomerCreatedEvent;

/**
* CustomerCreatedEventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.alibaba.cola.extension.test.customer.app;
package com.alibaba.cola.extension.customer.app;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.extension.test.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.test.customer.client.CustomerDTO;
import com.alibaba.cola.extension.test.customer.client.CustomerServiceI;
import com.alibaba.cola.extension.test.customer.client.GetOneCustomerQry;
import com.alibaba.cola.extension.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.customer.client.CustomerDTO;
import com.alibaba.cola.extension.customer.client.CustomerServiceI;
import com.alibaba.cola.extension.customer.client.GetOneCustomerQry;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* CustomerServiceImpl
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.alibaba.cola.extension.test.customer.app;
package com.alibaba.cola.extension.customer.app;

import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.extension.test.customer.client.GetOneCustomerQry;
import com.alibaba.cola.extension.customer.client.GetOneCustomerQry;
import org.springframework.stereotype.Component;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.alibaba.cola.extension.test.customer.app.extension;
package com.alibaba.cola.extension.customer.app.extension;

import com.alibaba.cola.extension.Extension;
import com.alibaba.cola.extension.test.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.test.customer.client.Constants;
import com.alibaba.cola.extension.test.customer.app.extensionpoint.AddCustomerValidatorExtPt;
import com.alibaba.cola.extension.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.customer.client.Constants;
import com.alibaba.cola.extension.customer.app.extensionpoint.AddCustomerValidatorExtPt;

/**
* AddCustomerBiz1UseCase1Scenario1Validator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.alibaba.cola.extension.test.customer.app.extension;
package com.alibaba.cola.extension.customer.app.extension;

import com.alibaba.cola.extension.Extension;
import com.alibaba.cola.extension.test.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.test.customer.client.Constants;
import com.alibaba.cola.extension.test.customer.app.extensionpoint.AddCustomerValidatorExtPt;
import com.alibaba.cola.extension.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.customer.client.Constants;
import com.alibaba.cola.extension.customer.app.extensionpoint.AddCustomerValidatorExtPt;

/**
* AddCustomerBiz1UseCase1Validator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.alibaba.cola.extension.test.customer.app.extension;
package com.alibaba.cola.extension.customer.app.extension;

import com.alibaba.cola.exception.BizException;
import com.alibaba.cola.extension.Extension;
import com.alibaba.cola.extension.test.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.test.customer.client.Constants;
import com.alibaba.cola.extension.test.customer.domain.CustomerType;
import com.alibaba.cola.extension.test.customer.app.extensionpoint.AddCustomerValidatorExtPt;
import com.alibaba.cola.extension.customer.client.AddCustomerCmd;
import com.alibaba.cola.extension.customer.client.Constants;
import com.alibaba.cola.extension.customer.domain.CustomerType;
import com.alibaba.cola.extension.customer.app.extensionpoint.AddCustomerValidatorExtPt;

/**
* AddCustomerBizOneValidator
Expand Down
Loading

0 comments on commit 8ec1631

Please sign in to comment.