小编hee*_*nee的帖子

在spring boot中使用testNG进行单元测试需要时间来构建项目

我在spring-boot中创建了一个Web应用程序.我正在使用testNG为我的业务层编写单元测试.

我创建了Application类

@SpringBootApplication
public class TestApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(TestApplication.class, args);
    }

    @Bean
    Mapper mapper()
    {
        List<String> mappingFiles = new ArrayList<String>();
        mappingFiles.add("dozer-mappings.xml");
        return new DozerBeanMapper(mappingFiles);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的测试类看起来像

@ContextConfiguration(classes = { TestApplication.class })
public class CommissionRuleServiceTest extends AbstractTestNGSpringContextTests
{
     @InjectMocks
     @Autowired
     MyService

     @Mock
     MyDAO;

     @BeforeMethod
     public void initMock()
     {
          MockitoAnnotations.initMocks(this);
     }

     @Test(dataProvider = "....")
     ......
     ......
}
Run Code Online (Sandbox Code Playgroud)

当我运行项目时,它会显示休息登录控制台,只需几次小测试就需要20.00秒.日志中的一些陈述是,

DEBUG oscisPathMatchingResourcePatternResolver - 搜索目录DEBUG oscaConfigurationClassPostProcessor DEBUG oscaClassPathBeanDefinitionScanner DEBUG oscisPathMatchingResourcePatternResolver DEBUG osbfsDefaultListableBeanFactory DEBUG oacbconverters.ArrayConverter DEBUG org.dozer.loader.xml.XMLParser DEBUG org.hibernate.cfg.SettingsFactory DEBUG …

java performance testng spring-boot

8
推荐指数
1
解决办法
732
查看次数

如何从本地存储库中包含 Maven 插件?

我有一个自定义插件,可以压缩我需要包含在我的 Maven 构建中的文件。所以我把这个插件包含在我的pom.xml

   <build>
        // Other tags
       <plugin>
            <groupId>someGroupId</groupId>
            <artifactId>somePlugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
      </plugins>
 </build>
Run Code Online (Sandbox Code Playgroud)

由于它是一个自定义插件,因此在任何公共 Maven 存储库中都不可用。因此,每当我尝试构建时,都会收到一条错误消息:

Failed to read artifact .....
Run Code Online (Sandbox Code Playgroud)

即使我已将它添加到我的本地存储库。我如何引用我本地存储库中的这个插件?

maven

7
推荐指数
1
解决办法
9089
查看次数

如何在Intellij IDEA中运行Applet?

我正在尝试为我的网络课程运行这些applet.当我尝试在浏览器中从链接运行这些时,他们什么也没做.所以我决定尝试在IntelliJ中编译它们,但是当我运行代码时它没有做任何事情.没有返回错误消息.我从源代码中更改代码的唯一方法是添加main方法并删除包声明.以下是我试图运行的Applet:

JAVA代码

///////////////////////////////////////
//LineSimApllet
//written by David Grangier, Institut Eurecom, France
//david.grangier@eurecom.fr
///////////////////////////////////////
//imports

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.applet.*;
import java.util.*;

//Applet Class
public class LineSimApplet extends Applet {
    //buttons
    Button start = new Button("Start");
    Button stop = new Button("Reset");
    //features lists
    MyChoice length = new MyChoice(new String[]{"10 km", "100 km", "1000 km"}, new double[]{10E3, 100E3, 1E6}, 3);
    MyChoice rate = new MyChoice(new String[]{"512 kps", "1 Mbps", "10 Mbps", "100 Mbps"}, new double[]{512E3, 1E6, 10E6, …
Run Code Online (Sandbox Code Playgroud)

java applet intellij-idea

7
推荐指数
2
解决办法
7280
查看次数

Chrome扩展弹出窗口中的Firebase身份验证

我正在尝试在Chrome扩展程序中使用身份验证(电子邮件/密码).如果我将我的身份验证代码放在后台脚本中,我似乎工作正常.但是我似乎无法将其作为浏览器动作脚本工作.

我使用以下代码作为我的扩展的基础:https://github.com/firebase/firebase-chrome-extension

我将browser_action.js更改为:

Firebase.enableLogging(true);
var f = new Firebase('https://myapp.firebaseio.com/');

f.authWithPassword({    
    email    : "a@b.cd",
    password : "1234"
}, function(error, authData) {
    if (error) {
        alert("Login Failed!", error);
} else {
    alert("Authenticated successfully with payload:", authData);
}
});
Run Code Online (Sandbox Code Playgroud)

我保持现有的browser_action.html不变:

<!doctype html>


<style type="text/css">
    #mainPopup {
        padding: 10px;
        height: 200px;
        width: 400px;
        font-family: Helvetica, Ubuntu, Arial, sans-serif;
    }
    h1 {
        font-size: 2em;
    }
</style>

<div id="mainPopup">
<h1>Firebase test!</h1>
<p>Clicks: <span id="contents"></span></p>
</div>

<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="browser_action.js"></script>
Run Code Online (Sandbox Code Playgroud)

当我加载扩展并单击图标时,它在控制台中给出以下错误:

Uncaught TypeError: …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension firebase firebase-authentication

7
推荐指数
2
解决办法
2324
查看次数

在同一个包和目录中找不到符号

我有两个课程,包括课程和课程.它们都在同一个包和同一目录中.

Offering.java:

package assignment02;

public class Offering implements Comparable<Offering> {
    private Course course;
    private int CRN;
    private int semester;

    public Offering(Course course, int CRN, int semester) {
        this.course = course;
        this.CRN = CRN;
        this.semester = semester;
    }

    public int getNumCredits() {
        return course.getNumCredits;
    }

    public int getCRN() {
        return CRN;
    }

    public int getSemester() {
        return semester;
    }

    public int compareTo(Offering other) {
        if(other == null) return - 1;
        return semester - other.semester;
    }
}
Run Code Online (Sandbox Code Playgroud)

Course.java:

package assignment02;

public class …
Run Code Online (Sandbox Code Playgroud)

java symbols compilation

6
推荐指数
1
解决办法
1万
查看次数

检测尚未在JDBC连接中提交的打开事务

如何检测事务是否保持打开状态,COMMIT或仍在ROLLBACKJDBC 连接上挂起?

我通过连接池获取连接对象。所以我想在使用之前检查连接的状态。

使用Postgres 9.x和Java 8。

java transactions connection-pooling jdbc

5
推荐指数
1
解决办法
4106
查看次数

在 Spock 中,如何从“then”块中消除重复的交互?

我正在使用 Spock 测试框架。我有很多测试的结构与此类似:

def "test"() {
    when:
    doSomething()
    then:
    1 * mock.method1(...)
    2 * mock.method2(...)
}
Run Code Online (Sandbox Code Playgroud)

我想将“then”块的代码移动到辅助方法中:

def assertMockMethodsInvocations() {
    1 * mock.method1(...)
    2 * mock.method2(...)
}
Run Code Online (Sandbox Code Playgroud)

然后调用这个辅助方法来消除我的规范中的代码重复,如下所示:

def "test"() {
    when:
    doSomething()
    then:
    assertMockMethodsInvocations()
}
Run Code Online (Sandbox Code Playgroud)

但是,在放入n * mock.method(...)辅助方法时,我无法匹配方法调用。以下示例演示:

// groovy code
class NoInvocationsDemo extends Specification {

    def DummyService service

    def "test"() {
        service = Mock()

        when:
        service.say("hello")
        service.say("world")

        then:
        assertService()
    }

    private assertService() {
        1 * service.say("hello")
        1 * service.say("world")
        true
    }

}

// java code
public …
Run Code Online (Sandbox Code Playgroud)

testing groovy spock

5
推荐指数
1
解决办法
663
查看次数

Lucene:使用DocValues添加字段时为null值

我通过搜索更改了文档字段以使其可排序,但现在addDocument()抛出一个异常,说明字段值为空,尽管我在添加字段时验证了该电子邮件是非空字符串.在异常之前Lucene代码binaryValue()从字段中获取.怀疑StringField构造函数不接受自定义FieldType.我可以使用String字段进行排序吗?如何解决这个问题?

Lucene 5.3.1

    private static final FieldType EMAIL_FIELD_TYPE = new FieldType(StringField.TYPE_STORED);
    static
    {
        EMAIL_FIELD_TYPE.setDocValuesType(DocValuesType.SORTED);
        EMAIL_FIELD_TYPE.freeze();
    }

    ...
        doc.add(new Field("email", email, EMAIL_FIELD_TYPE));
    ...
        writer.addDocument(doc);
        writer.commit();

java.lang.IllegalArgumentException: field "email": null value not allowed
    at org.apache.lucene.index.SortedDocValuesWriter.addValue(SortedDocValuesWriter.java:65)
    at org.apache.lucene.index.DefaultIndexingChain.indexDocValue(DefaultIndexingChain.java:435)
    at org.apache.lucene.index.DefaultIndexingChain.processField(DefaultIndexingChain.java:376)
    at org.apache.lucene.index.DefaultIndexingChain.processDocument(DefaultIndexingChain.java:300)
    at org.apache.lucene.index.DocumentsWriterPerThread.updateDocument(DocumentsWriterPerThread.java:234)
    at org.apache.lucene.index.DocumentsWriter.updateDocument(DocumentsWriter.java:450)
    at org.apache.lucene.index.IndexWriter.updateDocument(IndexWriter.java:1475)
    at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:1254)
Run Code Online (Sandbox Code Playgroud)

编辑:

此代码用于搜索:

Query q = new WildcardQuery(new Term("email", "*"));
Sort sort = new Sort(new SortField("email", SortField.Type.STRING));
TopDocs res = searcher.search(q, Integer.MAX_VALUE, sort);
Run Code Online (Sandbox Code Playgroud)

java lucene

4
推荐指数
1
解决办法
941
查看次数

Brother Label Printer SDK bPac 3.1 打印失败

我有打印机驱动程序、P-touch Editor、b-PAC 3.1 和客户端工具,都是 64 位的,从 Brother 网站下载并安装在我的 64 位 Windows 7 笔记本电脑上。P-touch Editor 工作/打印正常。

然而,b-PAC 失败了,并且没有一个样本起作用。我调试了代码:

bool b = doc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault);
Run Code Online (Sandbox Code Playgroud)

哪里b是假的。可能有什么问题?

printing sdk brother-bpac

2
推荐指数
1
解决办法
7442
查看次数

在 Java Web 应用程序中为设置的 cookie 添加 httponly 和安全标志

我想为 Cookie添加httponlysecure标志。为了实现它,我正在使用Filtersweb.xml.

添加标志的代码如下:

package com.crisil.dbconn;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.filters.SecurityWrapperResponse;

public class ClickjackFilter implements Filter 
{

    private String mode = "DENY";

    /**
     * Add X-FRAME-OPTIONS response header to tell IE8 (and any other browsers who
     * decide to implement) not to display this content in a frame. For details, please
     * …
Run Code Online (Sandbox Code Playgroud)

java security web.xml struts2 filter

2
推荐指数
1
解决办法
4万
查看次数