/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: AMLogTest.java,v 1.3 2008/06/25 05:44:19 qcheng Exp $
*
*/
/**
* This class tests the
* <code>com.sun.identity.log.LogRecord</code> and
* <code>com.sun.identity.log.Logger</code> classes.
*/
public AMLogTest() {
super("LogTest");
}
/**
* before running test:
* clean out the logfile (or remove it) - manual task
*
* @throws SSOException if the super administrator Single Sign On is
* invalid.
*/
// msgDatPrefixData is the "data" part of msgDataPrefix
/**
* the logging testng program currently consists of
* logging attempts by amadmin.
* logwrite-number-of-records records should be written.
*
* the log reading tests exercise the LogReader formats, with
* LogQuery and QueryElement classes.
*/
/**
* suiteSetup
* For setup, get:
* o a logger instance
*/
@Parameters({"logtest-realm"})
try {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
exiting("suiteSetup");
}
/**
* Before running the test(s), ensure:
* o the log svc config is set with buffer timer off, buff size = 1
*
* @throws Exception if an AMLogException occurs
*/
throws Exception {
try {
}
} else {
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
exiting("setup");
}
throws SSOException, SMSException {
"iPlanetAMLoggingService", adminSSOToken);
{
"iplanet-am-logging-time-buffering-status");
}
{
"iplanet-am-logging-buffer-size");
}
}
/**
* need:
* only the amadmin SSOToken (used in LogRecord), since
* can't (currently) use user SSOTokens. also means
* the log delegation can't be tested.
* column values
* data
* module_name
* domain
* log_level
* login_id
* ip_addr
* host_name
* message_id
* number of records to write
*
*/
@Parameters({"logwrite-data",
"logwrite-modulename",
"logwrite-domain",
"logwrite-log-level",
"logwrite-login-id",
"logwrite-ip-addr",
"logwrite-host-name",
"logwrite-message-id",
"logwrite-number-of-records"})
public void writeAdminLogRecord(
) throws AMLogException {
int numRecs = 0;
try {
} catch (NumberFormatException nfe) {
nfe.getMessage());
numRecs = 1;
}
}
/**
* DOMAIN, LOGIN_ID, IP_ADDR, and HOST_NAME are extracted from the
* SSOToken and added by the LogRecord handling. if any values are
* provided to the test, then they'll be added.
*/
int totalRecs = 0;
/*
* put variable data in ("msgDataPrefix + i") reverse
* order, so we can test sortBy in the read test.
*/
}
// ignore rLoginId parameter; use "amAdmin"
}
}
}
}
try {
totalRecs++;
} catch (AMLogException alex) {
// unexpected exception
alex.getMessage());
throw alex;
}
}
}
/**
* the amadmin read log record test. test reads as amadmin only.
*
* test 1: retrieve all records. *should* be
* logwrite-number-of-records
* if the logtest-logname exists before the whole run,
* then this test will fail (more than expected records
* retrieved).
*/
@Parameters({"logtest-logname",
"logwrite-number-of-records"})
dependsOnMethods = {"writeAdminLogRecord"})
throws AMLogException {
/*
* since "regular" user SSOToken stuff doesn't seem to work,
* just read as amadmin.
*
* there are a bunch of types of read tests to run...
* 1. read all
* 2. read selective (of various varieties)
*/
int numRecs = 0;
try {
} catch (NumberFormatException nfe) {
numRecs = 1;
}
}
}
throws AMLogException {
int numRecs = 0;
try {
} catch (AMLogException ale) {
throw new AMLogException("readAllRecords:AMLogException: " +
ale.getMessage());
} catch (NoSuchFieldException nsfe) {
throw new AMLogException("readAllRecords:NoSuchField: " +
nsfe.getMessage());
} catch (IOException ioe) {
throw new AMLogException("readAllRecords:IOException: " +
ioe.getMessage());
} catch (Exception e) {
throw new AMLogException("readAllRecords:Exception: " +
e.getMessage());
}
// first record has the column names
throw new AMLogException("Number of records read (" +
numRecs + ") doesn't match expected (" +
}
}
throws AMLogException
{
/*
* can have:
* LogQuery(), which sets:
* maxRecord = LogQuery.MOST_RECENT_MAX_RECORDS
* globalOperand = LogQuery.MATCH_ANY_CONDITION
* queries = null
* sortBy = null
* LogQuery(int max_record), which sets:
* maxRecord = max_record
* globalOperand = LogQuery.MATCH_ANY_CONDITION
* queries = null
* sortBy = null
* LogQuery(int max_record,
* int matchCriteria,
* String sortingBy), which sets:
* maxRecord = max_record
* globalOperand = matchCriteria
* sortBy = sortingBy
* queries = null
*
* use lq.addQuery(QueryElement qryElement) to
* add query elements to the LoqQuery's list of queries
* QueryElement(String fld, String val, int rel)
* fieldName = fld
* fieldValue = val
* relation = rel
* QueryElement()
* fieldName = new String()
* fieldValue = new String()
* relation = QueryElement.EQ
* use:
* QueryElement.setFieldName(String field)
* QueryElement.setFieldValue(String value)
* QueryElement.setRelation(int value)
*/
int totalRecsRead = 0;
/*
* test 1:
* all records, any condition, no sorting
* should be same as read all.
*/
null);
int numRecs = 0;
try {
} catch (AMLogException ale) {
throw new AMLogException("readLogQuery:AMLogException: " +
ale.getMessage());
} catch (NoSuchFieldException nsfe) {
throw new AMLogException("readLogQuery:NoSuchField: " +
nsfe.getMessage());
} catch (IllegalArgumentException iaex) {
throw new AMLogException("readLogQuery:IllegalArgumentException: "+
iaex.getMessage());
} catch (IOException ioe) {
throw new AMLogException("readLogQuery:IOException: " +
ioe.getMessage());
} catch (Exception e) {
throw new AMLogException("readLogQuery:Exception: " +
e.getMessage());
}
throw new AMLogException("Number of records read test 1 (" +
numRecs + ") doesn't match expected (" +
}
/*
* test 2:
* only read 2 most recent records
*/
numRecs = 0;
try {
} catch (AMLogException ale) {
throw new AMLogException("readLogQuery:AMLogException: " +
ale.getMessage());
} catch (NoSuchFieldException nsfe) {
throw new AMLogException("readLogQuery:NoSuchField: " +
nsfe.getMessage());
} catch (IllegalArgumentException iaex) {
throw new AMLogException("readLogQuery:IllegalArgumentException: "+
iaex.getMessage());
} catch (IOException ioe) {
throw new AMLogException("readLogQuery:IOException: " +
ioe.getMessage());
} catch (Exception e) {
throw new AMLogException("readLogQuery:Exception: " +
e.getMessage());
}
if (numRecs != 3) {
throw new AMLogException("Number of records read test 2 (" +
}
// two most recent should be "...data #1" and "...data #0"
throw new AMLogException("Read test 2: second most recent = " +
}
throw new AMLogException("Read test 2: most recent = " +
}
/*
* test 3:
* get records that end with "XX2" in the MessageID field.
* should only be one.
*/
null);
"XX2",
numRecs = 0;
try {
} catch (AMLogException ale) {
throw new AMLogException("readLogQuery:AMLogException: " +
ale.getMessage());
} catch (NoSuchFieldException nsfe) {
throw new AMLogException("readLogQuery:NoSuchField: " +
nsfe.getMessage());
} catch (IllegalArgumentException iaex) {
throw new AMLogException("readLogQuery:IllegalArgumentException: "+
iaex.getMessage());
} catch (IOException ioe) {
throw new AMLogException("readLogQuery:IOException: " +
ioe.getMessage());
} catch (Exception e) {
throw new AMLogException("readLogQuery:Exception: " +
e.getMessage());
}
if (numRecs != 2) {
throw new AMLogException("Number of records read test 3 (" +
}
// assume MessageID is in column 8 (starting from 0)
throw new AMLogException("Read test 3: record = " +
temp + ", not XX2");
}
/*
* test 4:
* get records that contain "data #4", "data #0" or "data #2"
* in the Data field. specify them in that order, with
* sort by Data field.
* msgDataPrefixData = "data #"
*/
"Data");
numRecs = 0;
try {
} catch (AMLogException ale) {
throw new AMLogException("readLogQuery:AMLogException: " +
ale.getMessage());
} catch (NoSuchFieldException nsfe) {
throw new AMLogException("readLogQuery:NoSuchField: " +
nsfe.getMessage());
} catch (IllegalArgumentException iaex) {
throw new AMLogException("readLogQuery:IllegalArgumentException: "+
iaex.getMessage());
} catch (IOException ioe) {
throw new AMLogException("readLogQuery:IOException: " +
ioe.getMessage());
} catch (Exception e) {
throw new AMLogException("readLogQuery:Exception: " +
e.getMessage());
}
if (numRecs != 4) {
throw new AMLogException("Number of records read test 4 (" +
}
/*
* gonna expect Data column is in result[x][1]. also
* that with sorting, result[1][1] contains "...data #0",
* result[2][1] contains "...data #2", and result[3][1]
* contains "...data #4".
*/
throw new AMLogException("Read test 4: first sorted record = " +
}
throw new AMLogException("Read test 4: second sorted record = " +
}
throw new AMLogException("Read test 4: third sorted record = " +
}
}
/*
* first record contains column names
*/
for (int i = 0; i < ii; i ++) {
}
for (int i = 1; i < numRecords; i++) {
"\nrecord " + i + " =");
for (int j = 0; j < ii; j++) {
":\t" + results[i][j]);
}
}
return;
}
// default to INFO
}
return logLevel;
}
/**
* tearDown
* undo what setup did
*/
@Parameters({})
public void tearDown()
throws Exception {
}
/**
* suiteTearDown
* undo what suiteSetup did:
* o set the realm's logging service's config back, if necessary
*/
@Parameters({"logtest-realm"})
}
}