-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improve] add unit test #2454
Open
yuluo-yx
wants to merge
21
commits into
apache:master
Choose a base branch
from
yuluo-yx:0804-yuluo/tets-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Improve] add unit test #2454
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
65c0522
[Improve] add unit tet
yuluo-yx dd22619
Merge branch 'master' into 0804-yuluo/tets-1
tomsun28 7133347
fix
yuluo-yx 723e6ae
Merge branch '0804-yuluo/tets-1' of https://github.com/yuluo-yx/hertz…
yuluo-yx a2b866d
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 84a4bff
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 00dbcbf
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx c9ba2e4
fix
yuluo-yx 9099d75
Merge branch '0804-yuluo/tets-1' of https://github.com/yuluo-yx/hertz…
yuluo-yx fdfbcaa
fix
yuluo-yx 4c9c82f
fix
yuluo-yx 1dfb83f
fix
yuluo-yx 3def4ef
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 827d723
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx f79f15e
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 35b6249
Merge branch 'master' into 0804-yuluo/tets-1
tomsun28 4c0fbe0
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 074b56b
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 3e3bbf7
Merge branch 'master' into 0804-yuluo/tets-1
yuluo-yx 88bb8ab
fix
yuluo-yx fa8681d
fix
yuluo-yx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
alerter/src/main/java/org/apache/hertzbeat/alert/config/JacksonConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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.alert.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.web.config.SpringDataJacksonConfiguration; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
|
||
/** | ||
* Jackson2Object configuration. | ||
* Fix: Resolved [org.springframework.http.converter.HttpMessageNotWritableException: | ||
* Could not write JSON: (was java.lang.UnsupportedOperationException)] | ||
* From: <a href="https://github.com/spring-projects/spring-data-commons/issues/2987#issuecomment-2072480592">...</a> | ||
*/ | ||
|
||
@Configuration | ||
public class JacksonConfiguration { | ||
|
||
@Bean | ||
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder(SpringDataJacksonConfiguration.PageModule pageModule) { | ||
|
||
return new Jackson2ObjectMapperBuilder().modules(pageModule); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertSilencesControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.alert.controller; | ||
|
||
import org.apache.hertzbeat.alert.service.AlertSilenceService; | ||
import org.apache.hertzbeat.common.constants.CommonConstants; | ||
import org.apache.hertzbeat.common.entity.alerter.AlertSilence; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; | ||
|
||
/** | ||
* test case for {@link AlertSilencesController} | ||
*/ | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AlertSilencesControllerTest { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Mock | ||
private AlertSilenceService alertSilenceService; | ||
|
||
private AlertSilence alertSilence; | ||
|
||
@InjectMocks | ||
private AlertSilencesController alertSilencesController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
|
||
this.mockMvc = standaloneSetup(alertSilencesController).build(); | ||
|
||
alertSilence = AlertSilence | ||
.builder() | ||
.id(1L) | ||
.type((byte) 1) | ||
.name("Test Silence") | ||
.build(); | ||
} | ||
|
||
@Test | ||
void testDeleteAlertDefines() throws Exception { | ||
|
||
doNothing().when(alertSilenceService).deleteAlertSilences(any()); | ||
|
||
mockMvc.perform(delete("/api/alert/silences") | ||
.param("ids", "1,2,3") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value((int) CommonConstants.SUCCESS_CODE)); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi,this will conflict with current existed
JacksonConfig
classThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, The json serialization piece doesn't look easy to fix. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about add
builder.modules(new SpringDataJacksonConfiguration.PageModule());
inJacksonConfig
like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, this would still report an error inside the unit test because the unit test is only tested against the current class. From the application level it won't.
Maybe there's another solution, let me research it and see 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 🤔 🤔 🤔 🤔