Skip to content

Commit

Permalink
[Improvement][Server] Add web mvc unit tests and fix dependencies (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangchong authored and laglangyue committed Sep 11, 2022
1 parent b46e76e commit 5db3e36
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 423 deletions.
12 changes: 4 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,13 @@
<version>${commons.logging.version}</version>
</dependency>

<!--springboot-->
<!-- springboot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
Expand Down
318 changes: 115 additions & 203 deletions seatunnel-dist/release-docs/LICENSE

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions seatunnel-server/seatunnel-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
<artifactId>seatunnel-app</artifactId>

<dependencies>

<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-common</artifactId>
<version>${project.version}</version>
</dependency>
<!--springboot-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -154,6 +158,11 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
Expand All @@ -170,7 +179,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.apache.seatunnel.app.domain.response.script.ScriptSimpleInfoRes;
import org.apache.seatunnel.app.service.IScriptService;
import org.apache.seatunnel.app.service.ITaskService;
import org.apache.seatunnel.app.util.Md5Utils;
import org.apache.seatunnel.app.utils.Md5Utils;
import org.apache.seatunnel.scheduler.dolphinscheduler.impl.InstanceServiceImpl;
import org.apache.seatunnel.server.common.PageData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.seatunnel.app.domain.response.user.UserSimpleInfoRes;
import org.apache.seatunnel.app.service.IRoleService;
import org.apache.seatunnel.app.service.IUserService;
import org.apache.seatunnel.app.util.PasswordUtils;
import org.apache.seatunnel.app.utils.PasswordUtils;
import org.apache.seatunnel.server.common.PageData;
import org.apache.seatunnel.server.common.SeatunnelException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.seatunnel.app.util;
package org.apache.seatunnel.app.utils;

import org.apache.seatunnel.app.common.Result;
import org.apache.seatunnel.server.common.SeatunnelErrorEnum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.seatunnel.app.util;
package org.apache.seatunnel.app.utils;

import org.springframework.util.DigestUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.seatunnel.app.util;
package org.apache.seatunnel.app.utils;

import org.springframework.util.DigestUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.seatunnel.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class WebMvcApplicationTest {

@LocalServerPort
protected int port;

@Autowired
protected MockMvc mockMvc;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.seatunnel.app.controller;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.apache.seatunnel.app.WebMvcApplicationTest;
import org.apache.seatunnel.app.common.Result;
import org.apache.seatunnel.app.dal.dao.impl.UserDaoImpl;
import org.apache.seatunnel.app.domain.request.user.AddUserReq;
import org.apache.seatunnel.app.domain.response.user.AddUserRes;
import org.apache.seatunnel.common.utils.JsonUtils;

import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;

public class UserControllerTest extends WebMvcApplicationTest {

@MockBean
private UserDaoImpl userDaoImpl;

@Test
public void testAdd() throws Exception {
AddUserReq requestDTO = new AddUserReq();
requestDTO.setUsername("admin");
requestDTO.setPassword("123456");
requestDTO.setStatus(new Byte("1"));
requestDTO.setType(new Byte("1"));
String url = "/api/v1/user/user";
when(this.userDaoImpl.add(Mockito.any())).thenReturn(1);
MvcResult mvcResult = mockMvc.perform(post(url).contentType(MediaType.APPLICATION_JSON).content(JsonUtils.toJsonString(requestDTO)))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn();
String result = mvcResult.getResponse().getContentAsString();
Result<AddUserRes> data = JsonUtils.parseObject(result, new TypeReference<Result<AddUserRes>>() {
});
Assertions.assertTrue(data.isSuccess());
Assertions.assertNotNull(data.getData());
}

}
Loading

0 comments on commit 5db3e36

Please sign in to comment.