2bittester/rbp-data-set huggingface dataset:
Question: How does the method seedDB work for RoomDB?
Answer:
public void seedDB() throws IOException, SQLException
{
    PreparedStatement ps = connection.prepareStatement(DELETE_ALL_ROOMS);
    ps.executeUpdate();
    PreparedStatement ps2 = connection.prepareStatement(RESET_INCREMENT);
    ps2.executeUpdate();
    executeSqlFile("seed.sql");
}
Question: How does the method executeSqlFile work for RoomDB?
Answer:
private void executeSqlFile(String filename) throws IOException, SQLException
{
    Reader reader = new InputStreamReader(new ClassPathResource(filename).getInputStream());
    Scanner sc = new Scanner(reader);
    StringBuffer sb = new StringBuffer();
    while (sc.hasNext()) {
        sb.append(sc.nextLine());
    }
    connection.prepareStatement(sb.toString()).executeUpdate();
}
Question: What package does RoomController belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for RoomController
Answer:
@RestController
public class RoomController {

}
Question: List variables declared in RoomController
Answer:
@Autowired
private RoomService roomService;
Question: How does the method getRooms work for RoomController?
Answer:
@RequestMapping
public ResponseEntity<Rooms> getRooms() throws SQLException
{
    Rooms rooms = roomService.getRooms();
    return ResponseEntity.status(HttpStatus.OK).body(rooms);
}
Question: How does the method getRoom work for RoomController?
Answer:
@RequestMapping
public ResponseEntity getRoom(@PathVariable(value = "id") int roomId) throws SQLException
{
    RoomResult roomResult = roomService.getSpecificRoom(roomId);
    return ResponseEntity.status(roomResult.getHttpStatus()).body(roomResult.getRoom());
}
Question: How does the method createRoom work for RoomController?
Answer:
@RequestMapping
public ResponseEntity<Room> createRoom(@Valid @RequestBody Room roomToCreate, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    RoomResult roomResult = roomService.createRoom(roomToCreate, token);
    return ResponseEntity.status(roomResult.getHttpStatus()).body(roomResult.getRoom());
}
Question: How does the method deleteRoom work for RoomController?
Answer:
@RequestMapping
public ResponseEntity deleteRoom(@PathVariable(value = "id") int roomId, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    RoomResult roomResult = roomService.deleteRoom(roomId, token);
    return ResponseEntity.status(roomResult.getHttpStatus()).build();
}
Question: How does the method updateRoom work for RoomController?
Answer:
@RequestMapping
public ResponseEntity<Room> updateRoom(@Valid @RequestBody Room roomToUpdate, @PathVariable(value = "id") int roomId, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    RoomResult roomResult = roomService.updateRoom(roomId, roomToUpdate, token);
    return ResponseEntity.status(roomResult.getHttpStatus()).body(roomResult.getRoom());
}
Question: How does the method openAPI work for SwaggerConfig?
Answer:
@Bean
public OpenAPI openAPI()
{
    return new OpenAPI().addServersItem(new Server().url("/room/"));
}
Question: How does the method publicApi work for SwaggerConfig?
Answer:
@Bean
public GroupedOpenApi publicApi()
{
    return GroupedOpenApi.builder().group("room-api").pathsToMatch("/**").build();
}
Question: What package does RoomApplication belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for RoomApplication
Answer:
@SpringBootApplication
@ComponentScan
public class RoomApplication {

}
Question: How does the method main work for RoomApplication?
Answer:
public static void main(String[] args)
{
    SpringApplication.run(RoomApplication.class, args);
}
Question: What package does RoomService belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for RoomService
Answer:
@Service
public class RoomService {

}
Question: List variables declared in RoomService
Answer:
@Autowired
private RoomDB roomDB;
Question: List variables declared in RoomService
Answer:
private AuthRequests authRequests;
Question: How does the method beginDbScheduler work for RoomService?
Answer:
@EventListener
public void beginDbScheduler()
{
    DatabaseScheduler databaseScheduler = new DatabaseScheduler();
    databaseScheduler.startScheduler(roomDB, TimeUnit.MINUTES);
}
Question: How does the method getRooms work for RoomService?
Answer:
public Rooms getRooms() throws SQLException
{
    return new Rooms(roomDB.queryRooms());
}
Question: How does the method getSpecificRoom work for RoomService?
Answer:
public RoomResult getSpecificRoom(int roomId) throws SQLException
{
    Room queriedRoom = roomDB.query(roomId);
    if (queriedRoom != null) {
        return new RoomResult(HttpStatus.OK, queriedRoom);
    } else {
        return new RoomResult(HttpStatus.NOT_FOUND);
    }
}
Question: How does the method createRoom work for RoomService?
Answer:
public RoomResult createRoom(Room roomToCreate, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        Room createdRoom = roomDB.create(roomToCreate);
        return new RoomResult(HttpStatus.CREATED, createdRoom);
    } else {
        return new RoomResult(HttpStatus.FORBIDDEN);
    }
}
Question: How does the method deleteRoom work for RoomService?
Answer:
public RoomResult deleteRoom(int roomId, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        if (roomDB.delete(roomId)) {
            return new RoomResult(HttpStatus.ACCEPTED);
        } else {
            return new RoomResult(HttpStatus.NOT_FOUND);
        }
    } else {
        return new RoomResult(HttpStatus.FORBIDDEN);
    }
}
Question: How does the method updateRoom work for RoomService?
Answer:
public RoomResult updateRoom(int roomId, Room roomToUpdate, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        Room updatedRoom = roomDB.update(roomId, roomToUpdate);
        if (updatedRoom != null) {
            return new RoomResult(HttpStatus.ACCEPTED, updatedRoom);
        } else {
            return new RoomResult(HttpStatus.NOT_FOUND);
        }
    } else {
        return new RoomResult(HttpStatus.FORBIDDEN);
    }
}
Question: What is the class declaration for DatabaseScheduler
Answer:
@Component
public class DatabaseScheduler {

}
Question: How does the method startScheduler work for DatabaseScheduler?
Answer:
public void startScheduler(RoomDB roomDB, TimeUnit timeUnit)
{
    if (resetCount > 0) {
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        Runnable r = () -> {
            if (!stop) {
                try {
                    logger.info("Resetting database");
                    roomDB.seedDB();
                } catch (Exception e) {
                    logger.error("Scheduler failed " + e.getMessage());
                }
            }
        };
        executor.scheduleAtFixedRate(r, 0L, resetCount, timeUnit);
    } else {
        logger.info("No env var was set for DB refresh (or set as 0) so not running DB reset");
    }
}
Question: How does the method getResetCount work for DatabaseScheduler?
Answer:
public int getResetCount()
{
    return resetCount;
}
Question: How does the method stepScheduler work for DatabaseScheduler?
Answer:
public void stepScheduler()
{
    stop = true;
}
Question: What package does ProxyServiceTest belong to
Answer:
package com.automationintesting;
Question: What is the class declaration for ProxyServiceTest
Answer:
public class ProxyServiceTest {

}
Question: How does the method reportPortIsReturned work for ProxyServiceTest?
Answer:
@Test
public void reportPortIsReturned()
{
    int port = proxyService.derivePortNumber("/report/");
    assertEquals(3005, port);
}
Question: How does the method mixedPathReturnsCorrectPath work for ProxyServiceTest?
Answer:
@Test
public void mixedPathReturnsCorrectPath()
{
    int port = proxyService.derivePortNumber("/report/room");
    assertEquals(3005, port);
}
Question: How does the method roomPortIsReturned work for ProxyServiceTest?
Answer:
@Test
public void roomPortIsReturned()
{
    int port = proxyService.derivePortNumber("/room/");
    assertEquals(3001, port);
}
Question: How does the method assetsPortIsReturn work for ProxyServiceTest?
Answer:
@Test
public void assetsPortIsReturn()
{
    int port = proxyService.derivePortNumber("/");
    assertEquals(3003, port);
}
Question: How does the method assetsPortIsReturnedForStaticAssests work for ProxyServiceTest?
Answer:
@Test
public void assetsPortIsReturnedForStaticAssests()
{
    int port = proxyService.derivePortNumber("/js/main.js");
    assertEquals(3003, port);
}
Question: What package does ProxyController belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for ProxyController
Answer:
@RestController
public class ProxyController {

}
Question: How does the method proxy work for ProxyController?
Answer:
@RequestMapping
public ResponseEntity<String> proxy(@RequestBody(required = false) String body, HttpMethod method, HttpServletRequest request) throws URISyntaxException
{
    return proxyService.passthroughRequest(body, method, request);
}
Question: What package does WebMvcConfig belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for WebMvcConfig
Answer:
@Configuration
public class WebMvcConfig {

}
Question: How does the method configurePathMatch work for WebMvcConfig?
Answer:
@Override
public void configurePathMatch(PathMatchConfigurer configurer)
{
    configurer.setUseSuffixPatternMatch(false);
}
Question: What package does ProxyApplication belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for ProxyApplication
Answer:
@SpringBootApplication
@ComponentScan
public class ProxyApplication {

}
Question: How does the method main work for ProxyApplication?
Answer:
public static void main(String[] args)
{
    SpringApplication.run(ProxyApplication.class, args);
}
Question: What package does ProxyService belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for ProxyService
Answer:
@Service
public class ProxyService {

}
Question: How does the method passthroughRequest work for ProxyService?
Answer:
public ResponseEntity<String> passthroughRequest(String body, HttpMethod method, HttpServletRequest request) throws URISyntaxException
{
    String requestUrl = request.getRequestURI();
    URI uri = new URI("http", null, "localhost", 0, null, null, null);
    int port = derivePortNumber(requestUrl);
    uri = UriComponentsBuilder.fromUri(uri).port(port).path(requestUrl).query(request.getQueryString()).build(true).toUri();
    HttpHeaders headers = new HttpHeaders();
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        if (!headerName.equals("accept-encoding")) {
            headers.set(headerName, request.getHeader(headerName));
        }
    }
    HttpEntity<String> httpEntity = new HttpEntity<>(body, headers);
    RestTemplate restTemplate = new RestTemplate();
    try {
        return restTemplate.exchange(uri, method, httpEntity, String.class);
    } catch (HttpStatusCodeException e) {
        return ResponseEntity.status(e.getRawStatusCode()).body(e.getResponseBodyAsString());
    }
}
Question: How does the method derivePortNumber work for ProxyService?
Answer:
public int derivePortNumber(String requestUrl)
{
    if (requestUrl.matches("^\\/booking\\/.*")) {
        return 3000;
    } else if (requestUrl.matches("^\\/branding\\/.*")) {
        return 3002;
    } else if (requestUrl.matches("^\\/auth\\/.*")) {
        return 3004;
    } else if (requestUrl.matches("^\\/report\\/.*")) {
        return 3005;
    } else if (requestUrl.matches("^\\/room\\/.*")) {
        return 3001;
    } else if (requestUrl.matches("^\\/message\\/.*")) {
        return 3006;
    } else {
        return 3003;
    }
}
Question: What package does TaskAnalysisTest belong to
Answer:
package com.automationintesting.unit.example;
Question: What is the class declaration for TaskAnalysisTest
Answer:
public class TaskAnalysisTest {

}
Question: How does the method testTokenCreation work for TaskAnalysisTest?
Answer:
@Test
public void testTokenCreation()
{
    Token token = new Token(new RandomString(16, ThreadLocalRandom.current()).nextString());
    String tokenString = token.getToken();
    assertThat(tokenString, is(instanceOf(String.class)));
    assertThat(tokenString.length(), is(16));
}
Question: What package does BaseTest belong to
Answer:
package com.automationintesting.unit.db;
Question: List variables declared in BaseTest
Answer:
protected AuthDB authDB;
Question: How does the method createRoomDB work for BaseTest?
Answer:
@BeforeAll
public static void createRoomDB() throws SQLException, IOException
{
    if (!dbOpen) {
        authDB = new AuthDB();
        dbOpen = true;
    }
    authDB.resetDB();
}
Question: What package does AuthDBTest belong to
Answer:
package com.automationintesting.unit.db;
Question: What is the class declaration for AuthDBTest
Answer:
public class AuthDBTest {

}
Question: How does the method testStoreToken work for AuthDBTest?
Answer:
@Test
public void testStoreToken() throws SQLException, IOException
{
    Token token = new Token("abc");
    Boolean tokenStored = authDB.insertToken(token);
    assertEquals(true, tokenStored);
}
Question: How does the method testQueryTokenExists work for AuthDBTest?
Answer:
@Test
public void testQueryTokenExists() throws SQLException
{
    Token token = new Token("abc");
    authDB.insertToken(token);
    Token retrievedToken = authDB.queryToken(token);
    assertEquals(token.getToken(), retrievedToken.getToken());
}
Question: How does the method testRemovingToken work for AuthDBTest?
Answer:
@Test
public void testRemovingToken() throws SQLException
{
    Token token = new Token("efg");
    authDB.insertToken(token);
    Boolean deleteSuccessful = authDB.deleteToken(token);
    assertEquals(true, deleteSuccessful);
}
Question: How does the method testQueryCredentials work for AuthDBTest?
Answer:
@Test
public void testQueryCredentials() throws SQLException
{
    Auth auth = new Auth("admin", "password");
    Boolean credentialQuary = authDB.queryCredentials(auth);
    assertEquals(true, credentialQuary);
}
Question: How does the method testQueryMissingCredentials work for AuthDBTest?
Answer:
@Test
public void testQueryMissingCredentials() throws SQLException
{
    Auth auth = new Auth("password", "admin");
    Boolean credentialQuary = authDB.queryCredentials(auth);
    assertEquals(false, credentialQuary);
}
Question: What package does AuthServiceTest belong to
Answer:
package com.automationintesting.unit.service;
Question: What is the class declaration for AuthServiceTest
Answer:
public class AuthServiceTest {

}
Question: List variables declared in AuthServiceTest
Answer:
@Mock
private AuthDB authDB;
Question: List variables declared in AuthServiceTest
Answer:
@Autowired
@InjectMocks
private AuthService authService;
Question: How does the method initialiseMocks work for AuthServiceTest?
Answer:
@BeforeEach
public void initialiseMocks()
{
    MockitoAnnotations.openMocks(this);
}
Question: How does the method testValidateCredentials work for AuthServiceTest?
Answer:
@Test
public void testValidateCredentials() throws SQLException
{
    Auth auth = new Auth("admin", "password");
    when(authDB.queryCredentials(auth)).thenReturn(true);
    when(authDB.insertToken(any())).thenReturn(true);
    Decision decision = authService.queryCredentials(auth);
    assertEquals(HttpStatus.OK, decision.getStatus());
    assertEquals(16, decision.getToken().getToken().length());
}
Question: How does the method testInvalidCredentials work for AuthServiceTest?
Answer:
@Test
public void testInvalidCredentials() throws SQLException
{
    Auth auth = new Auth("admin", "password");
    when(authDB.queryCredentials(auth)).thenReturn(false);
    Decision decision = authService.queryCredentials(auth);
    assertEquals(HttpStatus.FORBIDDEN, decision.getStatus());
}
Question: How does the method testErrorVerifyingCredentials work for AuthServiceTest?
Answer:
@Test
public void testErrorVerifyingCredentials() throws SQLException
{
    Auth auth = new Auth("admin", "password");
    when(authDB.queryCredentials(auth)).thenReturn(true);
    when(authDB.insertToken(any())).thenReturn(false);
    Decision decision = authService.queryCredentials(auth);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, decision.getStatus());
}
Question: How does the method testTokenPositiveVerification work for AuthServiceTest?
Answer:
@Test
public void testTokenPositiveVerification() throws SQLException
{
    Token token = new Token("abc");
    when(authDB.queryToken(token)).thenReturn(new Token("abc"));
    HttpStatus tokenIsValid = authService.verify(token);
    assertEquals(HttpStatus.OK, tokenIsValid);
}
Question: How does the method testTokenNegativeVerification work for AuthServiceTest?
Answer:
@Test
public void testTokenNegativeVerification() throws SQLException
{
    Token token = new Token("abc");
    when(authDB.queryToken(token)).thenReturn(null);
    HttpStatus tokenIsInvalid = authService.verify(token);
    assertEquals(HttpStatus.FORBIDDEN, tokenIsInvalid);
}
Question: How does the method testClearingToken work for AuthServiceTest?
Answer:
@Test
public void testClearingToken() throws SQLException
{
    Token token = new Token("efg");
    when(authDB.deleteToken(token)).thenReturn(true);
    HttpStatus tokenIsDeleted = authService.deleteToken(token);
    assertEquals(HttpStatus.OK, tokenIsDeleted);
}
Question: How does the method testUnableToClearToken work for AuthServiceTest?
Answer:
@Test
public void testUnableToClearToken() throws SQLException
{
    Token token = new Token("efg");
    when(authDB.deleteToken(token)).thenReturn(false);
    HttpStatus tokenIsDeleted = authService.deleteToken(token);
    assertEquals(HttpStatus.NOT_FOUND, tokenIsDeleted);
}
Question: What package does TaskAnalysisIntegrationTest belong to
Answer:
package com.automationintesting.integration.example;
Question: What is the class declaration for TaskAnalysisIntegrationTest
Answer:
@ExtendWith
@SpringBootTest
@ActiveProfiles
public class TaskAnalysisIntegrationTest {

}
Question: How does the method testLoginAPIEndpoint work for TaskAnalysisIntegrationTest?
Answer:
@Test
public void testLoginAPIEndpoint()
{
    Auth authPayload = new Auth("admin", "password");
    Response authResponse = given().contentType(ContentType.JSON).body(authPayload).post("http://localhost:3004/auth/login");
    assertNotEquals(404, authResponse.getStatusCode());
    assertEquals(String.class, authResponse.cookies().get("token").getClass());
}
Question: What package does AuthIntegrationTest belong to
Answer:
package com.automationintesting.integration;
Question: What is the class declaration for AuthIntegrationTest
Answer:
@ExtendWith
@SpringBootTest
@ActiveProfiles
public class AuthIntegrationTest {

}
Question: List variables declared in AuthIntegrationTest
Answer:
private Token token;
Question: How does the method createToken work for AuthIntegrationTest?
Answer:
@BeforeEach
public void createToken()
{
    Auth authPayload = new Auth("admin", "password");
    Response response = given().contentType(ContentType.JSON).body(authPayload).post("http://localhost:3004/auth/login");
    token = new Token(response.cookies().get("token"));
}
Question: How does the method testValidateEndpoint work for AuthIntegrationTest?
Answer:
@Test
public void testValidateEndpoint()
{
    Response response = given().contentType(ContentType.JSON).body(token).post("http://localhost:3004/auth/validate");
    assertEquals(200, response.getStatusCode());
}
Question: How does the method testLogoutEndpoint work for AuthIntegrationTest?
Answer:
@Test
public void testLogoutEndpoint()
{
    Response response = given().contentType(ContentType.JSON).body(token).post("http://localhost:3004/auth/logout");
    assertEquals(200, response.getStatusCode());
}
Question: What package does Auth belong to
Answer:
package com.automationintesting.model;
Question: What is the class declaration for Auth
Answer:
public class Auth {

}
Question: List variables declared in Auth
Answer:
@JsonProperty
private String username;
Question: List variables declared in Auth
Answer:
@JsonProperty
private String password;
Question: How does the method getUsername work for Auth?
Answer:
public String getUsername()
{
    return username;
}
Question: How does the method getPassword work for Auth?
Answer:
public String getPassword()
{
    return password;
}
Question: What package does Decision belong to
Answer:
package com.automationintesting.model;
Question: What is the class declaration for Decision
Answer:
public class Decision {

}
Question: List variables declared in Decision
Answer:
private HttpStatus httpStatus;
Question: List variables declared in Decision
Answer:
private Token token;
Question: How does the method getStatus work for Decision?
Answer:
public HttpStatus getStatus()
{
    return httpStatus;
}
Question: How does the method getToken work for Decision?
Answer:
public Token getToken()
{
    return token;
}
Question: What package does Token belong to
Answer:
package com.automationintesting.model;
Question: List variables declared in Token
Answer:
private String token;
Question: List variables declared in Token
Answer:
private Date expiry;
Question: How does the method getPreparedStatement work for Token?
Answer:
public PreparedStatement getPreparedStatement(Connection connection) throws SQLException
{
    final String CREATE_TOKEN = "INSERT INTO PUBLIC.TOKENS (token, expiry) VALUES(?, ?);";
    PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TOKEN);
    preparedStatement.setString(1, token);
    preparedStatement.setDate(2, expiry);
    return preparedStatement;
}
Question: How does the method createExpiryTimestamp work for Token?
Answer:
private Date createExpiryTimestamp()
{
    Calendar cal = Calendar.getInstance();
    cal.setTime(new java.util.Date());
    cal.add(Calendar.HOUR_OF_DAY, 1);
    return new Date(cal.getTime().getTime());
}
Question: What package does AuthDB belong to
Answer:
package com.automationintesting.db;
Question: What is the class declaration for AuthDB
Answer:
@Component
public class AuthDB {

}
Question: What is the variable DELETE_ALL_TOKENS assigned to in AuthDB?
Answer:
private String DELETE_ALL_TOKENS = "DELETE FROM TOKENS";
Question: What is the variable SELECT_BY_TOKEN assigned to in AuthDB?
Answer:
private String SELECT_BY_TOKEN = "SELECT * FROM TOKENS WHERE token = ?";
Question: What is the variable DELETE_BY_TOKEN assigned to in AuthDB?
Answer:
private String DELETE_BY_TOKEN = "DELETE FROM TOKENS WHERE token = ?";
Question: What is the variable SELECT_BY_CREDENTIALS assigned to in AuthDB?
Answer:
private String SELECT_BY_CREDENTIALS = "SELECT * FROM ACCOUNTS WHERE username = ? AND password = ?";
Question: List variables declared in AuthDB
Answer:
private Connection connection;
Question: What is the variable logger assigned to in AuthDB?
Answer:
private Logger logger = LoggerFactory.getLogger(AuthDB.class);
Question: How does the method insertToken work for AuthDB?
Answer:
public Boolean insertToken(Token token) throws SQLException
{
    PreparedStatement createPs = token.getPreparedStatement(connection);
    return createPs.executeUpdate() > 0;
}
Question: How does the method queryToken work for AuthDB?
Answer:
public Token queryToken(Token token) throws SQLException
{
    PreparedStatement ps = connection.prepareStatement(SELECT_BY_TOKEN);
    ps.setString(1, token.getToken());
    ResultSet result = ps.executeQuery();
    if (result.next()) {
        return new Token(result.getString("token"), result.getDate("expiry"));
    } else {
        return null;
    }
}
Question: How does the method deleteToken work for AuthDB?
Answer:
public Boolean deleteToken(Token token) throws SQLException
{
    PreparedStatement ps = connection.prepareStatement(DELETE_BY_TOKEN);
    ps.setString(1, token.getToken());
    int resultSet = ps.executeUpdate();
    return resultSet == 1;
}