You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by of...@apache.org on 2020/07/29 11:19:24 UTC

[incubator-dlab] branch develop updated: Updated test for AccessKeyService, created test for AccessKeyService

This is an automated email from the ASF dual-hosted git repository.

ofuks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new dc2d3b9  Updated test for AccessKeyService, created test for AccessKeyService
dc2d3b9 is described below

commit dc2d3b9370302440eab409d9ca8702d02479ad87
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Wed Jul 29 14:19:08 2020 +0300

    Updated test for AccessKeyService, created test for AccessKeyService
---
 .../service/impl/AccessKeyServiceImplTest.java     |  15 ++-
 .../service/impl/AuditServiceImplTest.java         | 106 +++++++++++++++++++++
 2 files changed, 118 insertions(+), 3 deletions(-)

diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AccessKeyServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AccessKeyServiceImplTest.java
index abd9fbb..f064c42 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AccessKeyServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AccessKeyServiceImplTest.java
@@ -23,6 +23,7 @@ import com.epam.dlab.auth.UserInfo;
 import com.epam.dlab.backendapi.conf.SelfServiceApplicationConfiguration;
 import com.epam.dlab.backendapi.resources.TestBase;
 import com.epam.dlab.backendapi.resources.dto.KeysDTO;
+import com.epam.dlab.exceptions.DlabException;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
@@ -50,8 +51,16 @@ public class AccessKeyServiceImplTest extends TestBase {
 
 		KeysDTO keysDTO = accessKeyService.generateKeys(userInfo);
 
-		assertEquals(USER.toLowerCase(), keysDTO.getUsername());
-		assertNotNull(keysDTO.getPublicKey());
-		assertNotNull(keysDTO.getPrivateKey());
+		assertEquals("Usernames are not equal", USER.toLowerCase(), keysDTO.getUsername());
+		assertNotNull("Public key is null", keysDTO.getPublicKey());
+		assertNotNull("Private key is null", keysDTO.getPrivateKey());
+	}
+
+	@Test(expected = DlabException.class)
+	public void generateKeysWithException() {
+		UserInfo userInfo = getUserInfo();
+		when(conf.getPrivateKeySize()).thenReturn(0);
+
+		accessKeyService.generateKeys(userInfo);
 	}
 }
\ No newline at end of file
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AuditServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AuditServiceImplTest.java
new file mode 100644
index 0000000..da0c002
--- /dev/null
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/AuditServiceImplTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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 com.epam.dlab.backendapi.service.impl;
+
+import com.epam.dlab.backendapi.dao.AuditDAO;
+import com.epam.dlab.backendapi.domain.AuditActionEnum;
+import com.epam.dlab.backendapi.domain.AuditCreateDTO;
+import com.epam.dlab.backendapi.domain.AuditDTO;
+import com.epam.dlab.backendapi.domain.AuditResourceTypeEnum;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.refEq;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AuditServiceImplTest {
+	private static final String USER = "user";
+	private static final String PROJECT = "project";
+	private static final String RESOURCE_NAME = "resourceName";
+	private static final String INFO = "info";
+
+	@Mock
+	private AuditDAO auditDAO;
+	@InjectMocks
+	private AuditServiceImpl auditService;
+
+	@Test
+	public void save() {
+		AuditDTO auditDTO = getAuditDTO();
+
+		auditService.save(auditDTO);
+
+		verify(auditDAO).save(refEq(auditDTO));
+	}
+
+	@Test
+	public void testSave() {
+		AuditCreateDTO auditCreateDTO = getAuditCreateDTO();
+
+		auditService.save(USER, auditCreateDTO);
+
+		verify(auditDAO).save(eq(getAuditDTO(USER, auditCreateDTO)));
+	}
+
+	@Test
+	public void getAudit() {
+		List<String> users = new ArrayList<>();
+		List<String> projects = new ArrayList<>();
+		List<String> resourceNames = new ArrayList<>();
+		List<String> resourceTypes = new ArrayList<>();
+		String dateStart = "";
+		String dateEnd = "";
+		int pageNumber = 1;
+		int pageSize = 10;
+
+		auditService.getAudit(users, projects, resourceNames, resourceTypes, dateStart, dateEnd, pageNumber, pageSize);
+
+		verify(auditDAO).getAudit(refEq(users), refEq(projects), refEq(resourceNames), refEq(resourceTypes), eq(dateStart), eq(dateEnd), eq(pageNumber), eq(pageSize));
+	}
+
+	private AuditDTO getAuditDTO() {
+		return AuditDTO.builder()
+				.user(USER)
+				.project(PROJECT)
+				.build();
+	}
+
+	private AuditDTO getAuditDTO(String user, AuditCreateDTO auditCreateDTO) {
+		return AuditDTO.builder()
+				.user(user)
+				.resourceName(auditCreateDTO.getResourceName())
+				.info(auditCreateDTO.getInfo())
+				.type(auditCreateDTO.getType())
+				.action(AuditActionEnum.FOLLOW_LINK)
+				.build();
+	}
+
+	private AuditCreateDTO getAuditCreateDTO() {
+		return new AuditCreateDTO(RESOURCE_NAME, INFO, AuditResourceTypeEnum.COMPUTE);
+	}
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org