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 6c19f17 [DLAB] AuditResource UT (#878) 6c19f17 is described below commit 6c19f1716c01fb32473f6e7002b09ebfcd3c53a2 Author: Pavel Papou <ppapo...@gmail.com> AuthorDate: Tue Sep 1 06:26:28 2020 -0400 [DLAB] AuditResource UT (#878) AuditResource unit test --- .../backendapi/resources/AuditResourceTest.java | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/AuditResourceTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/AuditResourceTest.java new file mode 100644 index 0000000..185b260 --- /dev/null +++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/resources/AuditResourceTest.java @@ -0,0 +1,88 @@ +/* + * 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.resources; + +import com.epam.dlab.backendapi.domain.AuditCreateDTO; +import com.epam.dlab.backendapi.domain.AuditResourceTypeEnum; +import com.epam.dlab.backendapi.service.AuditService; +import io.dropwizard.auth.AuthenticationException; +import io.dropwizard.testing.junit.ResourceTestRule; +import org.apache.http.HttpStatus; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.refEq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.eq; + +public class AuditResourceTest extends TestBase { + + private final static String USER = "testuser"; + private final static String INFO = "testInfo"; + private final static String RESOURCE = "testResource"; + + private final AuditService auditService = mock(AuditService.class); + + @Rule + public final ResourceTestRule resources = getResourceTestRuleInstance(new AuditResource(auditService)); + + @Before + public void setup() throws AuthenticationException { + authSetup(); + } + + @Test + public void saveAudit() { + final Response response = resources.getJerseyTest() + .target("/audit") + .request() + .header("Authorization", "Bearer " + TOKEN) + .post(Entity.json(prepareAuditCreateDTO())); + + assertEquals(HttpStatus.SC_OK, response.getStatus()); + verify(auditService).save(eq(USER), refEq(prepareAuditCreateDTO())); + verifyNoMoreInteractions(auditService); + } + + @Test + public void getAudit() { + final Response response = resources.getJerseyTest() + .target("/audit") + .request() + .header("Authorization", "Bearer " + TOKEN) + .get(); + + assertEquals(HttpStatus.SC_OK, response.getStatus()); + assertEquals(MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE)); + } + + private AuditCreateDTO prepareAuditCreateDTO() { + return new AuditCreateDTO(RESOURCE, INFO,AuditResourceTypeEnum.COMPUTE); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org