小编Mik*_*iar的帖子

如何模拟事件处理程序?

我为 Stash 编写了一个事件处理程序,以通过消息总线架构发送消息。这是我fedmsgEventListener班上的一个例子:

@EventListener
public void opened(PullRequestOpenedEvent event)
{
    HashMap<String, Object> message = prExtracter(event);
    String originProjectKey = ((HashMap<String, Object>)message.get("source")).get("project_key").toString();
    String originRepo = ((HashMap<String, Object>)message.get("source")).get("repository").toString();
    String topic = originProjectKey + "." + originRepo + ".pullrequest.opened";
    sendMessage(topic, message);
}
Run Code Online (Sandbox Code Playgroud)

它获取一个事件,从中提取信息,根据事件中的信息构造一个主题,并调用一个方法来发送消息。我需要为所有这些事件处理程序编写单元测试。

这是运行我试图实现的第一个测试的类:

import org.junit.Test;
import com.cray.stash.MyPluginComponent;
import com.cray.stash.MyPluginComponentImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class MyComponentUnitTest
{
    @Test
    public void testMyName()
    {
        MyPluginComponent component = new MyPluginComponentImpl(null);       
        assertTrue(component.openPullRequest().contains(".pullrequest.opened"));
    }
}
Run Code Online (Sandbox Code Playgroud)

然后这里是测试调用的类和方法:

import com.atlassian.sal.api.ApplicationProperties;
import com.atlassian.stash.event.pull.*;
import org.mockito.Mock;
import static org.mockito.Mockito.*; …
Run Code Online (Sandbox Code Playgroud)

java events junit mockito

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

JUnit 用于带有 while 循环的方法

我在为带有 While 循环的方法编写 JUnit 测试时遇到一些困难。我的方法如下所示:

private void deleteMethod(DeleteRequest dr){

    // below statement am calling some service which returns me a object after querying it from Database.
    SomeObject ob = db.getdata(dr);

    while(ob != null) {
        // this method deletes the Data from DB 
        db.deleteData(ob);
        // again calling the same service operation as we did before while loop. I have a situation where my service only returns single record at a time. It is avoidable that I need to do a dirty …
Run Code Online (Sandbox Code Playgroud)

mockito

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

从C#调用存储过程时出错

我有以下c#代码来调用存储过程testproc,但是当我运行这个应用程序时,它说它找不到存储过程testproc.

这是我调用存储过程的c#代码:

SqlConnection con = new SqlConnection();
con.ConnectionString = "data source='example.com';user id='sa';password='password';persist security info=False;initial catalog=Test;Connect Timeout=100; Min Pool Size=100; Max Pool Size=500";
con.Open();

DataSet ds = new DataSet();
SqlCommand com = new SqlCommand("testproc",con );
SqlDataAdapter sqlda = new SqlDataAdapter(com);
//sqlda.SelectCommand.CommandText = "SELECT Id,Name1,ZipCode,StreetName,StreetNumber,State1,Lat,Lng,Keyword, ( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS(  (Lat/57.2958)  ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN(  Lat/57.2958  ) ) ) AS distance FROM Business_Details where( (StreetName …
Run Code Online (Sandbox Code Playgroud)

c# sql ado.net stored-procedures sql-server-2005

3
推荐指数
2
解决办法
8218
查看次数

使用java将Element对象写入文件

我有Element类的数据.我正在尝试将其值写入文件,但我遇到了麻烦:

< Some process to acquire values into the variable "fieldData" >

// Prepare file output
FileWriter fstream = new FileWriter("C:/output.txt");
BufferedWriter out = new BufferedWriter(fstream);

Element field = fieldData.getElement(i);

out.write(field);  // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String
Run Code Online (Sandbox Code Playgroud)

关于我应该如何处理这个案子的任何建议?另外,对于我来说,看到(即打印到屏幕)可用的静态变量和与对象相关的方法的最佳方法是什么?谢谢.

更多代码片段以帮助调试:

private static final Name SECURITY_DATA = new Name("securityData");
private static final Name FIELD_DATA = new Name("fieldData");

Element securityDataArray = msg.getElement(SECURITY_DATA); // …
Run Code Online (Sandbox Code Playgroud)

java bloomberg data-structures

3
推荐指数
1
解决办法
2107
查看次数

触摸的绘制线在COCOS2D中移动

我正在使用COCOS2D为iPhone开发游戏.

在那里,当用户将手指从一个点拖到另一个点时,我需要绘制一条线.据我所知,我需要Touches Moved method从中获得积分.

但我不知道该怎么做.有人可以帮我这个吗?

iphone cocos2d-iphone ios touchmove

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

如何在SSIS数据流任务中跟踪成功处理或失败的行的状态?

我有一个非常简单的数据流任务从FF读取数据并将数据插入表中.同时我想在Audit表中写入,插入了多少行,创建日期......

我怎么能这么容易呢?

audit ssis

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

困惑于java if else表现

我正在对方法的性能进行调查,最后发现开销是由if else语句的"else"部分引起的.我编写了一个小程序来说明性能差异,即使代码的else部分永远不会被执行:

public class TestIfPerf
{
    public static void main( String[] args )
    {   
        boolean condition = true; 
        long time = 0L;
        int value = 0;
        // warm up test 
        for( int count=0; count<10000000; count++ )
        {       
            if ( condition ) 
            {           
                value = 1 + 2;  
            }           
            else        
            {           
                value = 1 + 3;  
            }           
        }       
        // benchmark if condition only
        time = System.nanoTime();
        for( int count=0; count<10000000; count++ )
        {
            if ( condition )
            {
                value = 1 …
Run Code Online (Sandbox Code Playgroud)

java performance

3
推荐指数
1
解决办法
1008
查看次数

C#上不允许使用默认参数说明符错误

当我构建项目时,VC#表示不允许使用Default参数说明符.它引导我到这个代码:

public class TwitterResponse
{
    private readonly RestResponseBase _response;
    private readonly Exception _exception;

    internal TwitterResponse(RestResponseBase response, Exception exception = null)
    {
        _exception = exception;
        _response = response;
    }
Run Code Online (Sandbox Code Playgroud)

可能是我的错误?

c# .net-3.5 default-parameters

3
推荐指数
1
解决办法
6795
查看次数

如何查找和配置SSIS包所需的参数以从代码中执行它们

我想从C#代码执行位于服务器上的SSIS包.

我试图让这个运行:

public void Execute()
{
    string folderName = "MYFOLDER";
    string projectName = "MYPROJECT";
    string serverName = @"MYSERVER\REGION";

    String connectionString = String.Format("Data Source={0};Initial Catalog=msdb;Integrated Security=SSPI;", serverName);

    using(SqlConnection sqlConnection = new SqlConnection(connectionString)) {
        IntegrationServices integrationServices = new IntegrationServices(sqlConnection);

        Catalog catalog = integrationServices.Catalogs["SSISDB"];
        CatalogFolder catalogFolder = catalog.Folders[folderName];

        PackageInfo package = catalogFolder.Projects[projectName].Packages[PackageName];


        PackageInfo.ExecutionValueParameterSet batchIdParameter = new PackageInfo.ExecutionValueParameterSet {
            ObjectType = package.Parameters["BatchId"].ObjectType,
            ParameterName = "BatchId",
            ParameterValue = package.Parameters["BatchId"].DesignDefaultValue
        };
        PackageInfo.ExecutionValueParameterSet dateIdParameter = new PackageInfo.ExecutionValueParameterSet
        {
            ObjectType = package.Parameters["DateId"].ObjectType,
            ParameterName = "DateId",
            ParameterValue = package.Parameters["DateId"].DesignDefaultValue …
Run Code Online (Sandbox Code Playgroud)

c# sql-server ssis

3
推荐指数
1
解决办法
2803
查看次数

转换vs转换SQL Server

我一直在使用SQL Server中的datetime列.现在大多数时候我必须将日期时间的时间部分重置为'00:00:00.000'.

我使用cast函数来实现相同的目的:

select cast(cast(getdate() as date)as datetime)
Run Code Online (Sandbox Code Playgroud)

现在我的其他团队成员使用其他功能:

select cast(floor(cast(GETDATE() as float))as datetime)
Run Code Online (Sandbox Code Playgroud)

要么

SELECT CONVERT(VARCHAR,GETDATE(),105)
Run Code Online (Sandbox Code Playgroud)

我应该记住哪个函数要记住索引列是日期时间类型列.(因此我使用强制转换两次转换datetime - > date - > datetime).

sql datetime casting type-conversion sql-server-2012

3
推荐指数
1
解决办法
1215
查看次数