Skip to content

Commit

Permalink
CODE Make Testing module work gradle
Browse files Browse the repository at this point in the history
report generates

Signed-off-by: Andres LeonRangel <[email protected]>
  • Loading branch information
aleon1220 committed Dec 7, 2023
1 parent 4699db8 commit b9e64fe
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 148 deletions.
40 changes: 20 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
version: '3'
services:
openldap:
# https://github.com/osixia/docker-openldap
# https://www.openldap.org
image: osixia/openldap:1.2.4
environment:
LDAP_ORGANISATION: "IT Latinos NZ"
LDAP_DOMAIN: "latintech.org"
LDAP_ADMIN_PASSWORD: ${LDAP_ADMIN_PASS}
ports:
- 389:389
- 636:636
volumes:
- ./ldap:/var/lib/ldap
- ./ldap:/etc/ldap/slapd.d
webapp:
image: aleon1220/soa:latest
ports:
- 8080:8080
version: '3'
services:
openldap:
# https://github.com/osixia/docker-openldap
# https://www.openldap.org
image: osixia/openldap:1.2.4
environment:
LDAP_ORGANISATION: "IT Latinos NZ"
LDAP_DOMAIN: "latintech.org"
LDAP_ADMIN_PASSWORD: ${LDAP_ADMIN_PASS}
ports:
- 389:389
- 636:636
volumes:
- ./ldap:/var/lib/ldap
- ./ldap:/etc/ldap/slapd.d
webapp:
image: aleon1220/soa:latest
ports:
- 8080:8080
47 changes: 23 additions & 24 deletions src/main/java/service/GenerateQRCode.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package service;

import java.io.IOException;
import java.nio.file.Paths;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

public class GenerateQRCode {

public void createWebsiteQRCode() throws WriterException, IOException {
String qrData = "www.andres.nz";
String localPath = "/home/aleonrangel";
boolean validateQR = false;

BitMatrix matrix = new MultiFormatWriter().encode(qrData, BarcodeFormat.QR_CODE, 500, 500, null);
MatrixToImageWriter.writeToPath(matrix, "png", Paths.get(localPath), null);
System.out.println("QR code created");
validateQR = true;
}
}
package service;

import java.io.IOException;
import java.nio.file.Paths;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

public class GenerateQRCode {
public boolean validateQR = false;

public void createWebsiteQRCode() throws WriterException, IOException {
String qrData = "www.andres.nz";
String localPath = "/home/aleonrangel";
BitMatrix matrix = new MultiFormatWriter().encode(qrData, BarcodeFormat.QR_CODE, 500, 500, null);
MatrixToImageWriter.writeToPath(matrix, "png", Paths.get(localPath), null);
System.out.println("QR code created");
validateQR = true;
}
}
23 changes: 16 additions & 7 deletions src/test/java/auth/ldap/TestLDAPAuthentication.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package auth.ldap;

import org.junit.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;

import org.mockito.Mockito;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPSearchException;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
Expand All @@ -20,7 +25,7 @@ public class TestLDAPAuthentication {
// - Verifies expected methods are called on the mocks

@Test
public void testMockOpenLDAPAdminSearch() {
public void testMockOpenLDAPAdminSearch() throws LDAPSearchException {
// Mock LDAPConnection
LDAPConnection connectionMock = Mockito.mock(LDAPConnection.class);

Expand All @@ -32,16 +37,21 @@ public void testMockOpenLDAPAdminSearch() {
// Mock search result entries
SearchResultEntry entry1 = Mockito.mock(SearchResultEntry.class);
SearchResultEntry entry2 = Mockito.mock(SearchResultEntry.class);

SearchResultEntry[] ldapResult = new SearchResultEntry[] { entry1, entry2 };
List<SearchResultEntry> resultList = Arrays.asList(ldapResult);
// Stub searchEntries to return mocked entries
Mockito.when(searchResultMock.getSearchEntries()).thenReturn(new SearchResultEntry[] { entry1, entry2 });
Mockito.when(searchResultMock.getSearchEntries()).thenReturn(resultList);

// Test the method
AuthenticateOpenLDAP ldapAuth = new AuthenticateOpenLDAP();
ldapAuth.openLDAPAdminSearch();

// Verify search was called
Mockito.verify(connectionMock).search(Mockito.anyString(), Mockito.any(), Mockito.anyString());
try {
Mockito.verify(connectionMock).search(Mockito.anyString(), Mockito.any(), Mockito.anyString());
} catch (LDAPSearchException e) {
e.printStackTrace();
}

// Verify entry processing
Mockito.verify(entry1).toLDIFString();
Expand All @@ -53,15 +63,14 @@ public void testMockOpenLDAPAdminSearch() {

@Test
public void testOpenLDAPAdminSearch_withOpenLDAP() {

// Test parameters
String ldapURL = "ldap://localhost";
String ldapHost = "localhost";
int ldapPort = 389;
String bindDN = "cn=admin,dc=my-company,dc=com";
var bindPassword = "adminpassword";
String baseDN = "dc=my-company,dc=com";
String searchFilter = "(objectClass=*)";
String searchFilter = "(objectClass=*)";

// Connect to OpenLDAP
// Establishing a connection to the LDAP server
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/auth/login/LoginReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public void setAuthenticationResult(AuthenticationResult authenticationResult) {
public String toString() {
// return getClass()+"challenge"+challengeParameters+"data in
// authent"+authenticationResult.getIdToken();
return getClass() + " Not obtaining really much";
return getClass() + "JSON Overriding functionality";
}
}
11 changes: 1 addition & 10 deletions src/test/java/json/TestConversionJSON2Object.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package attendance.gson;
package json;

import com.google.gson.Gson;

Expand All @@ -7,24 +7,15 @@
public class TestConversionJSON2Object {

public static void main(String[] args) {
// TODO Auto-generated method stub: use a variable for the token

String replyJson = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFl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EJwwHbV7oBeQQlA6pYXvWvRwpj0col8N904w4QxoNNNEtYxIYbLtJkj3w-ZogJ9VPkKL_B3ayKTfle3nQ-PHrXyzYpBK89h39Hp2IiOddY-Ihl8iVuj8RziTUiMZ-0jTOToCAa8gQ813DGAtca0i4ffw3hg\"}}";

String jsonInString = "{'name' : 'martina perumal'}";

Gson gson = new Gson();

// Restaurant restaurantObject = gson.fromJson(restaurantJson,
// Restaurant.class);
LoginReply loginReplyObject = gson.fromJson(replyJson, LoginReply.class);

// Object loginReplyObject = gson.fromJson(replyJson, Object.class);

Girl girl = gson.fromJson(jsonInString, Girl.class);

System.out.println("value " + loginReplyObject.getAuthenticationResult().getIdToken());
System.out.println("value of her name " + girl.getName());
// System.out.println("obtain token "+ loginReplyObject.authenticationResult);
}
}
1 change: 1 addition & 0 deletions src/test/java/json/TestConversionJson2Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class TestConversionJson2Map {
public void convertJSON2Map() {
String jsonFromMS = "{\"ChallengeParameters\":{},\"AuthenticationResult\":{\"AccessToken\":\"eyJraWQiOiJ6M2pWR1lscDVsS2VHVzRXMkwrU3BtdjN4UzIwWGFCU1FvZFlvdWg1WkU4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI2MWI5ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImp0aSI6ImI4MzY3ZjcwLTA5MDktNGI0Mi1hNDI2LWM2ZTYyY2M3ZTI0YSIsImNsaWVudF9pZCI6IjFlOHRlZm1sY2wyaDI5M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ZTI4NC1kMzVhLTQ0M2YtOTlhNy04MGY0OWE4YTI4NmQiLCJhdWQiOiIxZTh0ZWZtbGNsMmgyOTB2bmg5cmNlZm52ciIsImNvZ25pdG86Z3JvdXBzIjpbImFkbWluaXN0cmF0b3IiXSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTA4NTg2OSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfMEhkMUtvTTVhIiwiY29nbml0bzp1c2VybmFtZSI6IjEwMjk1NzY1IiwiZXhwIjoxNTA1MDg5NDY5LCJpYXQiOjE1MDUwODU4NjksImVtYWlsIjoiam9uYXRoYW4udEB4dHJhLmNvLm56In0.N2vUTeKskoSGGnZNNQkoJrjqQSTwCRsAyoVzU8HoSESciE97PbHu_rsDBHdlIvExQgZOJUDH2fi2ZTVXL0qw_dw_1oy5PY0ss6iF9Ya8vNvwJ4QIg0nGLJEEWO6y9h81bUiy8WYOyC0uCy4FKPBzxu-VjO_ZkJwQZLlhkx56cPXhQI9JFbwQDeyxJDF9duOGiZkWYmiG842TeYpaNIiW46KtQ8kiZLGre9qUdPjQv9S-Ch9Cm8bDqVSunAVtTityUJMGJuxhM78hPAujGdeNfMX0qEx37MpKbQtkb_xJZaT1c0IXnu1tneqtGVxZtaZdQ4mUlBmdzamQaWhlSXvqyA\"}}";
String jsonInString = "{'name' : 'Alejandra Rangel'}";

Gson gson = new Gson();
Type authorization = new TypeToken<Map<String, Authorization>>() {
Expand Down
Loading

0 comments on commit b9e64fe

Please sign in to comment.