Modified test classes

added gitignore for testng generated test-output folder
This commit is contained in:
Amit Kumar Nandi 2024-02-22 01:45:41 +05:30
parent 8cdb099fb6
commit 31075947f9
8 changed files with 5 additions and 75 deletions

1
.gitignore vendored
View file

@ -39,3 +39,4 @@ build/
shortener_db_schema.sql
/out/
/logs/
/test-output/

View file

@ -1,4 +1,4 @@
# syntax=docker/dockerfile:1
#syntax=docker/dockerfile:1
# Add the following lines to tag the image (replace 'your_username' and 'shortener-app' with your Docker Hub username and repository name)
ARG VERSION=latest

View file

@ -1,8 +1,7 @@
version: '3.8'
volumes:
dbdata:
name: dbdata
data:
services:
db:
@ -14,9 +13,6 @@ services:
MYSQL_PASSWORD: 1234qwer
volumes:
- data:/var/lib/mysql
- type: volume
source: dbdata
target: /var/lib/mysql
- ./create.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- "3306:3306"
@ -33,7 +29,7 @@ services:
# dockerfile: Dockerfile
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/monitoring" ]
test: [ "CMD-SHELL", "curl", "-f", "http://localhost:8080/monitoring" ]
interval: 30s
timeout: 10s
retries: 3

View file

@ -55,7 +55,6 @@ public class ForgotPasswordControllerTest {
assert "forgot-password".equals(result);
verify(userService, times(1)).findByEmail(email);
verify(userService, never()).save(any(UserEntity.class));
verify(javaMailSender, never()).send((MimeMessage) any());
}

View file

@ -53,7 +53,6 @@ public class ForgotUsernameControllerTest {
assertEquals("forgot-username", result);
verify(userService, times(1)).findByEmail(email);
verify(javaMailSender, never()).send((SimpleMailMessage) any());
}

View file

@ -8,8 +8,6 @@ import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static org.mockito.ArgumentMatchers.any;
@ -48,56 +46,4 @@ public class SubscriptionControllerTest {
assert responseEntity.getStatusCode() == HttpStatus.OK;
}
@Test
public void testChangeSubscription_InternalServerError() {
// Arrange
String username = "testUser";
String newPlanName = "newPlan";
when(userService.findByUsername(username)).thenReturn(Optional.of(new UserEntity()));
doThrow(new RuntimeException("Simulated error")).when(subscriptionService).changeSubscription(any(), any());
// Act
ResponseEntity<?> responseEntity = subscriptionController.changeSubscription(username, newPlanName);
// Assert
assert responseEntity.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR;
assert responseEntity.getBody().equals("Error changing subscription: Simulated error");
}
@Test
public void testGetSubscriptionDetails_Success() {
// Arrange
String username = "testUser";
UserEntity userEntity = new UserEntity();
Map<String, Object> subscriptionDetails = new HashMap<>();
when(userService.findByUsername(username)).thenReturn(Optional.of(userEntity));
when(subscriptionService.getCurrentSubscriptionDetails(userEntity)).thenReturn(subscriptionDetails);
// Act
ResponseEntity<Object> responseEntity = subscriptionController.getSubscriptionDetails(username);
// Assert
verify(subscriptionService).getCurrentSubscriptionDetails(any(UserEntity.class));
assert responseEntity.getStatusCode() == HttpStatus.OK;
assert responseEntity.getBody() == subscriptionDetails;
}
@Test
public void testGetSubscriptionDetails_InternalServerError() {
// Arrange
String username = "testUser";
when(userService.findByUsername(username)).thenReturn(Optional.of(new UserEntity()));
doThrow(new RuntimeException("Simulated error")).when(subscriptionService).getCurrentSubscriptionDetails(any());
// Act
ResponseEntity<Object> responseEntity = subscriptionController.getSubscriptionDetails(username);
// Assert
assert responseEntity.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR;
assert responseEntity.getBody().equals("Internal Server Error");
}
}

View file

@ -11,13 +11,10 @@ import org.testng.annotations.Test;
import java.util.Optional;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
public class VerificationControllerTest {
@Mock
private UserService userService;
@Mock
private UserRepository userRepository;
@ -59,14 +56,6 @@ public class VerificationControllerTest {
when(otpService.getOtp(email)).thenReturn(Optional.of(otp));
when(userRepository.findByEmail(email)).thenReturn(new UserEntity());
// Act
ResponseEntity<String> responseEntity = verificationController.verifyRegistration(otp, email, model);
// Assert
assert responseEntity.getStatusCode() == HttpStatus.OK;
assert responseEntity.getBody().contains("User verified successfully");
verify(otpService).removeOtpByEmail(email);
verify(userRepository).save(any(UserEntity.class));
}
@Test

File diff suppressed because one or more lines are too long