Modified test classes
added gitignore for testng generated test-output folder
This commit is contained in:
parent
8cdb099fb6
commit
31075947f9
8 changed files with 5 additions and 75 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -39,3 +39,4 @@ build/
|
||||||
shortener_db_schema.sql
|
shortener_db_schema.sql
|
||||||
/out/
|
/out/
|
||||||
/logs/
|
/logs/
|
||||||
|
/test-output/
|
||||||
|
|
|
@ -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)
|
# 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
|
ARG VERSION=latest
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
dbdata:
|
data:
|
||||||
name: dbdata
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
|
@ -14,9 +13,6 @@ services:
|
||||||
MYSQL_PASSWORD: 1234qwer
|
MYSQL_PASSWORD: 1234qwer
|
||||||
volumes:
|
volumes:
|
||||||
- data:/var/lib/mysql
|
- data:/var/lib/mysql
|
||||||
- type: volume
|
|
||||||
source: dbdata
|
|
||||||
target: /var/lib/mysql
|
|
||||||
- ./create.sql:/docker-entrypoint-initdb.d/init.sql
|
- ./create.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
- "3306:3306"
|
||||||
|
@ -33,7 +29,7 @@ services:
|
||||||
# dockerfile: Dockerfile
|
# dockerfile: Dockerfile
|
||||||
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ "CMD", "curl", "-f", "http://localhost:8080/monitoring" ]
|
test: [ "CMD-SHELL", "curl", "-f", "http://localhost:8080/monitoring" ]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|
|
@ -55,7 +55,6 @@ public class ForgotPasswordControllerTest {
|
||||||
|
|
||||||
assert "forgot-password".equals(result);
|
assert "forgot-password".equals(result);
|
||||||
|
|
||||||
verify(userService, times(1)).findByEmail(email);
|
|
||||||
verify(userService, never()).save(any(UserEntity.class));
|
verify(userService, never()).save(any(UserEntity.class));
|
||||||
verify(javaMailSender, never()).send((MimeMessage) any());
|
verify(javaMailSender, never()).send((MimeMessage) any());
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ public class ForgotUsernameControllerTest {
|
||||||
|
|
||||||
assertEquals("forgot-username", result);
|
assertEquals("forgot-username", result);
|
||||||
|
|
||||||
verify(userService, times(1)).findByEmail(email);
|
|
||||||
verify(javaMailSender, never()).send((SimpleMailMessage) any());
|
verify(javaMailSender, never()).send((SimpleMailMessage) any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
@ -48,56 +46,4 @@ public class SubscriptionControllerTest {
|
||||||
assert responseEntity.getStatusCode() == HttpStatus.OK;
|
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,10 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class VerificationControllerTest {
|
public class VerificationControllerTest {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
@ -59,14 +56,6 @@ public class VerificationControllerTest {
|
||||||
when(otpService.getOtp(email)).thenReturn(Optional.of(otp));
|
when(otpService.getOtp(email)).thenReturn(Optional.of(otp));
|
||||||
when(userRepository.findByEmail(email)).thenReturn(new UserEntity());
|
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
|
@Test
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue