package org.owasp.dependencycheck.analyzer;

import org.apache.commons.io.IOUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.Engine;
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
import org.owasp.dependencycheck.data.nodeaudit.Advisory;
import org.owasp.dependencycheck.data.nodeaudit.NpmAuditParser;
import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.utils.Settings;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class PnpmAuditAnalyzerTest extends BaseTest
{

    @Test
    public void testNpmAuditParserCompatibility() throws IOException, JSONException
    {
        NpmAuditParser npmAuditParser = new NpmAuditParser();
        JSONObject vulnsAuditJson = new JSONObject(IOUtils.toString(getResourceAsStream(this, "pnpmaudit/pnpm-audit.json"), "UTF-8"));
        List<Advisory> advisories = npmAuditParser.parse(vulnsAuditJson);
        assertThat(advisories.size(), is(1));
    }

    @Test
    public void testSupportsFiles() {
        PnpmAuditAnalyzer analyzer = new PnpmAuditAnalyzer();
        assertThat(analyzer.accept(new File("package-lock.json")), is(false));
        assertThat(analyzer.accept(new File("npm-shrinkwrap.json")), is(false));
        assertThat(analyzer.accept(new File("yarn.lock")), is(false));
        assertThat(analyzer.accept(new File("pnpm-lock.yaml")), is(true));
    }

    @Test
    public void testDependencyCheck() throws AnalysisException
    {
        PnpmAuditAnalyzer analyzer = new PnpmAuditAnalyzer();
        Dependency dependency = new Dependency(new File("src/test/resources/pnpmaudit/pnpm-lock.yaml"));

        Properties properties = new Properties();
        properties.setProperty(Settings.KEYS.ANALYZER_PNPM_AUDIT_ENABLED, "true");
        final Settings settings = new Settings(properties);
        final Engine engine = new Engine(settings);
        analyzer.initialize(settings);
        analyzer.analyzeDependency(dependency, engine);
        assertThat(true, is(true));
    }
}

@@ -1212,9 +1212,9 @@
  is(
-1
+2
 ));%0A
@@ -1553,32 +1553,32 @@
 )), is(false));%0A
+
         assertTh
@@ -1645,637 +1645,7 @@
    %7D
-%0A%0A    @Test%0A    public void testDependencyCheck() throws AnalysisException%0A    %7B%0A        PnpmAuditAnalyzer analyzer = new PnpmAuditAnalyzer();%0A        Dependency dependency = new Dependency(new File(%22src/test/resources/pnpmaudit/pnpm-lock.yaml%22));%0A%0A        Properties properties = new Properties();%0A        properties.setProperty(Settings.KEYS.ANALYZER_PNPM_AUDIT_ENABLED, %22true%22);%0A        final Settings settings = new Settings(properties);%0A        final Engine engine = new Engine(settings);%0A        analyzer.initialize(settings);%0A        analyzer.analyzeDependency(dependency, engine);%0A        assertThat(true, is(true));%0A    %7D
 %0A%7D%0A

remove integration test as it is duplicative with what is in the IT already