Skip to content

Commit

Permalink
[improve] Add GeneralConfigTypeEnum. (apache#2555)
Browse files Browse the repository at this point in the history
Co-authored-by: Calvin <[email protected]>
  • Loading branch information
MRgenial and Calvin979 authored Aug 18, 2024
1 parent 4fdc048 commit 7ac21d3
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 org.apache.hertzbeat.common.constants;

/**
* General Config Type Enum
*/
public enum GeneralConfigTypeEnum {

/**
* template config
*/
template,

/**
* system secret config
*/
secret,

/**
* sms general config
*/
sms,

/**
* system config
*/
system,

/**
* mail general config
*/
email,

/**
* system store config
*/
oss;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.lang.reflect.Type;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.EmailNoticeSender;
import org.springframework.stereotype.Service;
Expand All @@ -46,7 +47,7 @@ public MailGeneralConfigServiceImpl(GeneralConfigDao generalConfigDao, ObjectMap

@Override
public String type() {
return "email";
return GeneralConfigTypeEnum.email.name();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.reflect.Type;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.ObjectStoreConfigChangeEvent;
import org.apache.hertzbeat.manager.pojo.dto.ObjectStoreDTO;
Expand Down Expand Up @@ -63,7 +64,7 @@ public ObjectStoreConfigServiceImpl(GeneralConfigDao generalConfigDao, ObjectMap

@Override
public String type() {
return "oss";
return GeneralConfigTypeEnum.oss.name();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.lang.reflect.Type;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.SmsNoticeSender;
import org.springframework.stereotype.Service;
Expand All @@ -46,7 +47,7 @@ public SmsGeneralConfigServiceImpl(GeneralConfigDao generalConfigDao, ObjectMapp

@Override
public String type() {
return "sms";
return GeneralConfigTypeEnum.sms.name();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.annotation.Resource;
import java.lang.reflect.Type;
import java.util.Objects;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.common.support.event.SystemConfigChangeEvent;
import org.apache.hertzbeat.common.util.TimeZoneUtil;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void handler(SystemConfig systemConfig) {

@Override
public String type() {
return "system";
return GeneralConfigTypeEnum.system.name();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.lang.reflect.Type;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.SystemSecret;
import org.springframework.stereotype.Service;
Expand All @@ -43,7 +44,7 @@ public SystemSecretServiceImpl(GeneralConfigDao generalConfigDao, ObjectMapper o

@Override
public String type() {
return "secret";
return GeneralConfigTypeEnum.secret.name();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import java.lang.reflect.Type;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.TemplateConfig;
import org.apache.hertzbeat.manager.service.AppService;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void handler(TemplateConfig templateConfig) {

@Override
public String type() {
return "template";
return GeneralConfigTypeEnum.template.name();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;

import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.pojo.dto.EmailNoticeSender;
import org.apache.hertzbeat.manager.pojo.dto.ObjectStoreDTO;
import org.apache.hertzbeat.manager.pojo.dto.TemplateConfig;
Expand Down Expand Up @@ -57,9 +59,9 @@ public class ConfigServiceTest {
@BeforeEach
public void setUp() {
List<GeneralConfigService> generalConfigServices = new ArrayList<>();
when(objectStoreConfigService.type()).thenReturn("oss");
when(templateConfigService.type()).thenReturn("template");
when(mailGeneralConfigService.type()).thenReturn("mail");
when(objectStoreConfigService.type()).thenReturn(GeneralConfigTypeEnum.oss.name());
when(templateConfigService.type()).thenReturn(GeneralConfigTypeEnum.template.name());
when(mailGeneralConfigService.type()).thenReturn(GeneralConfigTypeEnum.email.name());
generalConfigServices.add(objectStoreConfigService);
generalConfigServices.add(templateConfigService);
generalConfigServices.add(mailGeneralConfigService);
Expand All @@ -68,22 +70,22 @@ public void setUp() {

@Test
public void testSaveConfig() {
configService.saveConfig("oss", new ObjectStoreDTO<>());
configService.saveConfig(GeneralConfigTypeEnum.oss.name(), new ObjectStoreDTO<>());
verify(objectStoreConfigService, times(1)).saveConfig(any(ObjectStoreDTO.class));

configService.saveConfig("mail", new EmailNoticeSender());
configService.saveConfig(GeneralConfigTypeEnum.email.name(), new EmailNoticeSender());
verify(mailGeneralConfigService, times(1)).saveConfig(any(EmailNoticeSender.class));
}

@Test
public void testGetConfig() {
ObjectStoreDTO ossConfig = new ObjectStoreDTO<>();
when(objectStoreConfigService.getConfig()).thenReturn(ossConfig);
assertNotNull(configService.getConfig("oss"));
assertNotNull(configService.getConfig(GeneralConfigTypeEnum.oss.name()));

EmailNoticeSender emailNoticeSender = new EmailNoticeSender();
when(mailGeneralConfigService.getConfig()).thenReturn(emailNoticeSender);
configService.getConfig("mail");
configService.getConfig(GeneralConfigTypeEnum.email.name());
verify(mailGeneralConfigService, times(1)).getConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.EmailNoticeSender;
import org.apache.hertzbeat.manager.service.impl.MailGeneralConfigServiceImpl;
Expand Down Expand Up @@ -54,7 +55,7 @@ void setUp() {
@Test
void testType() {

assertEquals("email", mailGeneralConfigService.type());
assertEquals(GeneralConfigTypeEnum.email.name(), mailGeneralConfigService.type());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hertzbeat.manager.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.pojo.dto.ObjectStoreConfigChangeEvent;
import org.apache.hertzbeat.manager.pojo.dto.ObjectStoreDTO;
import org.apache.hertzbeat.manager.service.impl.ObjectStoreConfigServiceImpl;
Expand Down Expand Up @@ -66,7 +67,7 @@ void setUp() {
void testGetType() {

String type = objectStoreConfigService.type();
assertEquals("oss", type);
assertEquals(GeneralConfigTypeEnum.oss.name(), type);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.SmsNoticeSender;
import org.apache.hertzbeat.manager.service.impl.SmsGeneralConfigServiceImpl;
Expand Down Expand Up @@ -60,7 +61,7 @@ void setUp() {
@Test
void testType() {
String result = service.type();
assertEquals("sms", result);
assertEquals(GeneralConfigTypeEnum.sms.name(), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.SystemConfig;
import org.apache.hertzbeat.manager.service.impl.SystemGeneralConfigServiceImpl;
Expand Down Expand Up @@ -58,7 +59,7 @@ void setUp() {
void testType() {

String result = service.type();
assertEquals("system", result);
assertEquals(GeneralConfigTypeEnum.system.name(), result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.SystemSecret;
import org.apache.hertzbeat.manager.service.impl.SystemSecretServiceImpl;
Expand Down Expand Up @@ -54,7 +55,7 @@ void setUp() {
@Test
void testType() {

assertEquals("secret", systemSecretService.type());
assertEquals(GeneralConfigTypeEnum.secret.name(), systemSecretService.type());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hertzbeat.manager.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hertzbeat.common.constants.GeneralConfigTypeEnum;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.TemplateConfig;
import org.apache.hertzbeat.manager.service.impl.TemplateConfigServiceImpl;
Expand Down Expand Up @@ -88,7 +89,7 @@ void testHandlerNullTemplateConfig() {
void testType() {

String type = templateConfigServiceImpl.type();
assertEquals("template", type);
assertEquals(GeneralConfigTypeEnum.template.name(), type);
}

}

0 comments on commit 7ac21d3

Please sign in to comment.