/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2016 The ZAP development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zaproxy.zap.testutils;

import java.util.ArrayList;
import java.util.List;

import net.htmlparser.jericho.Source;

import org.junit.Before;

import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.zap.extension.alert.ExtensionAlert;
import org.zaproxy.zap.extension.pscan.PassiveScanThread;
import org.zaproxy.zap.extension.pscan.PluginPassiveScanner;

/**
 * Class with utility/helper methods for passive scanner tests ({@link org.zaproxy.zap.extension.pscan.PluginPassiveScanner
 * PluginPassiveScanner}).
 * 
 * @param <T> the type of the passive scanner.
 */
public abstract class PassiveScannerTestUtils<T extends PluginPassiveScanner> extends TestUtils {

    protected T rule;
    protected PassiveScanThread parent;
    protected List<Alert> alertsRaised;

    public PassiveScannerTestUtils() {
        super();
    }

    @Before
    public void setUp() throws Exception {
        setUpZap();

        alertsRaised = new ArrayList<>();
        parent = new PassiveScanThread(null, null, new ExtensionAlert(), null) {
            @Override
            public void raiseAlert(int arg0, Alert arg1) {
                alertsRaised.add(arg1);
            }
        };
        rule = createScanner();
        rule.setParent(parent);
    }

    protected abstract T createScanner();
    
    protected Source createSource(HttpMessage msg) {
        return new Source(msg.getResponseBody().toString());
    }

}
@@ -766,16 +766,202 @@
 utils;%0A%0A
+import static org.hamcrest.Matchers.equalTo;%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.hamcrest.Matchers.isEmptyOrNullString;%0Aimport static org.junit.Assert.assertThat;%0A%0A
 import j
@@ -1279,16 +1279,71 @@
 Thread;%0A
+import org.zaproxy.zap.extension.pscan.PassiveScanner;%0A
 import o
@@ -1662,22 +1662,16 @@
 extends 
-Plugin
 PassiveS
@@ -2129,12 +2129,10 @@
 int 
-arg0
+id
 , Al
@@ -2140,15 +2140,58 @@
 rt a
-rg1
+lert
 ) %7B%0A
+                defaultAssertions(alert);%0A
     
@@ -2224,11 +2224,12 @@
 dd(a
-rg1
+lert
 );%0A 
@@ -2319,24 +2319,352 @@
 nt);%0A    %7D%0A%0A
+    protected void defaultAssertions(Alert alert) %7B%0A        if (rule instanceof PluginPassiveScanner) %7B%0A            PluginPassiveScanner pps = (PluginPassiveScanner) rule;%0A            assertThat(alert.getPluginId(), is(equalTo(pps.getPluginId())));%0A        %7D%0A        assertThat(alert.getAttack(), isEmptyOrNullString());%0A    %7D%0A%0A
     protecte

Add default assertions to passive alerts