Skip to content
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

[Improvement-16773][Parameter] Create project parameters-Field modify user adds default value #16775

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public Result createProjectParameter(User loginUser, long projectCode, String pr
.code(CodeGenerateUtils.genCode())
.projectCode(projectCode)
.userId(loginUser.getId())
.operator(loginUser.getId())
.createTime(now)
.updateTime(now)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dolphinscheduler.api.service.impl.ProjectParameterServiceImpl;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.dao.entity.ProjectParameter;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.task.api.enums.DataType;

Expand All @@ -47,12 +48,17 @@ public class ProjectParameterControllerTest {
@Test
public void testCreateProjectParameter() {
User loginUser = getGeneralUser();
Result successResult = getSuccessResult();
successResult.setData(getProjectParameter());

Mockito.when(projectParameterService.createProjectParameter(Mockito.any(), Mockito.anyLong(), Mockito.any(),
Mockito.any(), Mockito.any())).thenReturn(getSuccessResult());
Mockito.any(), Mockito.any())).thenReturn(successResult);
Result result = projectParameterController.createProjectParameter(loginUser, 1, "key", "value",
DataType.VARCHAR.name());
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode());

ProjectParameter projectParameter = (ProjectParameter) result.getData();
Assertions.assertEquals(1, projectParameter.getOperator());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assertions.assertEquals(1, projectParameter.getOperator());
Assertions.assertEquals(loginUser.getId(), projectParameter.getOperator());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this UT have any help to this case? You need to add UT to ProjectParameterService and avoid mocking the result.

Copy link
Contributor Author

@sdhzwc sdhzwc Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful because if the creation is successful, it will return projectParameter. By verifying whether the modify user is the expected value, we can determine if the addition was successful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you revert the change of projectParameterService the case still pass.

Copy link
Contributor Author

@sdhzwc sdhzwc Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you revert the change of projectParameterService the case still pass.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I means since the projectParameterService.createProjectParameter has been mocked, so the test case is meaningless, it can just test the api call is work but cannot test the logic in projectParameterService.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I means since the projectParameterService.createProjectParameter has been mocked, so the test case is meaningless, it can just test the api call is work but cannot test the logic in projectParameterService

The adjustment has been made, this should be suitable now

}

@Test
Expand Down Expand Up @@ -122,4 +128,16 @@ private Result getSuccessResult() {
return result;
}

private ProjectParameter getProjectParameter() {
User loginUser = getGeneralUser();
ProjectParameter projectParameter = new ProjectParameter();
projectParameter.setProjectCode(1);
projectParameter.setParamName("key");
projectParameter.setParamValue("value");
projectParameter.setParamDataType(DataType.VARCHAR.name());
projectParameter.setUserId(loginUser.getId());
projectParameter.setOperator(loginUser.getId());
return projectParameter;
}

}
Loading