Dosyaları "/" dizinine yükle

This commit is contained in:
2024-12-06 22:45:43 +03:00
commit 127b2a2ee9
5 changed files with 328 additions and 0 deletions

263
AccessControlTest.java Normal file
View File

@@ -0,0 +1,263 @@
package test.java;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import main.java.AccessControl;
public class AccessControlTest {
private AccessControl ac;
@Before
public void setUp() {
ac = new AccessControl();
}
/**
* ---------------------------
* DECISION TABLE TESTS
* ---------------------------
* Based on the conditions, an example decision table was:
*
* Variables:
* isEmployee (E) : {T, F}
* hasSpecialAuth (A): {T, F}
* isAuditor (R): {T, F}
* hourOfDay (H): test with {8,9,16,17}
* isWeekend (W): {T, F}
*
* Example table entries (just a sample):
*
* # | E | A | R | H | W | Expected
* --|---|---|---|----|----|---------
* 1 | F | F | F | 9 | F | false (not employee, not auditor)
* 2 | T | F | F | 9 | F | true (employee, working hours, weekday)
* 3 | T | T | F | 8 | F | true (employee + special auth, no time restriction)
* 4 | T | F | F | 17 | F | false (employee but after working hours and no special auth)
* 5 | T | F | F | 9 | T | false (employee during working hours but weekend)
* 6 | F | F | T | 9 | T | true (auditor during working hours, weekend allowed)
* 7 | F | F | T | 8 | F | false (auditor outside working hours)
* 8 | T | T | F | 17 | T | true (employee with special auth, no restrictions)
*/
@Test
public void testDecisionTable1() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, false, 9, false);
long end = System.nanoTime();
System.out.println("testDecisionTable1 duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testDecisionTable2() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 9, false);
long end = System.nanoTime();
System.out.println("testDecisionTable2 duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testDecisionTable3() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, true, false, 8, false);
long end = System.nanoTime();
System.out.println("testDecisionTable3 duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testDecisionTable4() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 17, false);
long end = System.nanoTime();
System.out.println("testDecisionTable4 duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testDecisionTable5() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 9, true);
long end = System.nanoTime();
System.out.println("testDecisionTable5 duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testDecisionTable6() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, true, 9, true);
long end = System.nanoTime();
System.out.println("testDecisionTable6 duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testDecisionTable7() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, true, 8, false);
long end = System.nanoTime();
System.out.println("testDecisionTable7 duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testDecisionTable8() {
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, true, false, 17, true);
long end = System.nanoTime();
System.out.println("testDecisionTable8 duration (ns): " + (end - start));
assertTrue(result);
}
/**
* ---------------------------
* EQUIVALENCE PARTITIONING TESTS
* ---------------------------
* Equivalence classes could be:
* - isEmployee: {employee, not employee}
* - hasSpecialAuth (only matters if employee): {special auth, no special auth}
* - isAuditor: {auditor, not auditor}
* - hourOfDay: {before working hours (<9), during working hours (916), after working hours (>16)}
* - isWeekend: {weekend, weekday}
*
* Choose representative combinations:
* 1) Not employee, not auditor, during working hours, weekday -> expected false
* 2) Employee, no special auth, not auditor, during working hours, weekday -> expected true
* 3) Employee, special auth, any hour, weekend -> expected true (special auth overrides)
* 4) Auditor, during working hours, weekend -> expected true (no weekend restriction)
* 5) Auditor, before working hours, weekday -> expected false
*/
@Test
public void testEquivalence1() {
// Not employee, not auditor, working hours (10), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, false, 10, false);
long end = System.nanoTime();
System.out.println("testEquivalence1 duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testEquivalence2() {
// Employee, no special auth, not auditor, working hours (10), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 10, false);
long end = System.nanoTime();
System.out.println("testEquivalence2 duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testEquivalence3() {
// Employee, special auth, after hours (17), weekend
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, true, false, 17, true);
long end = System.nanoTime();
System.out.println("testEquivalence3 duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testEquivalence4() {
// Auditor, during working hours (16), weekend
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, true, 16, true);
long end = System.nanoTime();
System.out.println("testEquivalence4 duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testEquivalence5() {
// Auditor, before working hours (8), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, true, 8, false);
long end = System.nanoTime();
System.out.println("testEquivalence5 duration (ns): " + (end - start));
assertFalse(result);
}
/**
* ---------------------------
* BOUNDARY VALUE TESTS
* ---------------------------
* Boundary values around working hours: 8 (just before), 9 (start), 16 (end), 17 (just after)
* Test with employee, auditor, and special auth where appropriate.
*/
@Test
public void testBoundaryBeforeWorkHoursEmployee() {
// Employee, no special auth, hour=8 (before start), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 8, false);
long end = System.nanoTime();
System.out.println("testBoundaryBeforeWorkHoursEmployee duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testBoundaryStartWorkHoursEmployee() {
// Employee, no special auth, hour=9 (start), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 9, false);
long end = System.nanoTime();
System.out.println("testBoundaryStartWorkHoursEmployee duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testBoundaryEndWorkHoursEmployee() {
// Employee, no special auth, hour=16 (end), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 16, false);
long end = System.nanoTime();
System.out.println("testBoundaryEndWorkHoursEmployee duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testBoundaryAfterWorkHoursEmployee() {
// Employee, no special auth, hour=17 (after end), weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, false, false, 17, false);
long end = System.nanoTime();
System.out.println("testBoundaryAfterWorkHoursEmployee duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testBoundaryAuditorBeforeHours() {
// Auditor, hour=8, weekend/weekday doesn't matter, let's pick weekday
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, true, 8, false);
long end = System.nanoTime();
System.out.println("testBoundaryAuditorBeforeHours duration (ns): " + (end - start));
assertFalse(result);
}
@Test
public void testBoundaryAuditorStartHours() {
// Auditor, hour=9, weekend true
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(false, false, true, 9, true);
long end = System.nanoTime();
System.out.println("testBoundaryAuditorStartHours duration (ns): " + (end - start));
assertTrue(result);
}
@Test
public void testBoundarySpecialAuthAnyTime() {
// Employee with special auth, hour=8, weekend=true
long start = System.nanoTime();
boolean result = ac.isAccessAllowed(true, true, false, 8, true);
long end = System.nanoTime();
System.out.println("testBoundarySpecialAuthAnyTime duration (ns): " + (end - start));
assertTrue(result);
}
}