summaryrefslogtreecommitdiffstats
path: root/docs/teaching/demos/spacewar/src/coordination/Coordinator.java
Commit message (Expand)AuthorAgeFilesLines
* Adding scrubbed demos (figures & spacewar), scripts, slides, and Eclipse proj...mkersten2003-11-101-0/+449
a> 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
# frozen_string_literal: true

# Redmine - project management software
# Copyright (C) 2006-  Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

require_relative '../test_helper'

class RepositoriesSubversionControllerTest < Redmine::RepositoryControllerTest
  tests RepositoriesController

  fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules,
           :repositories, :issues, :issue_statuses, :changesets, :changes,
           :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers

  PRJ_ID = 3
  NUM_REV = 16

  def setup
    super
    Setting.default_language = 'en'
    User.current = nil

    @project = Project.find(PRJ_ID)
    @repository = Repository::Subversion.create(:project => @project,
               :url => self.class.subversion_repository_url)
    assert @repository
  end

  if repository_configured?('subversion')
    def test_new
      @request.session[:user_id] = 1
      @project.repository.destroy
      get(
        :new,
        :params => {
          :project_id => 'subproject1',
          :repository_scm => 'Subversion'
        }
      )
      assert_response :success
      assert_select 'select[name=?]', 'repository_scm' do
        assert_select 'option[value=?][selected=selected]', 'Subversion'
      end
    end

    def test_show
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :show,
        :params => {
          :id => PRJ_ID
        }
      )
      assert_response :success

      assert_select 'table.entries tbody' do
        assert_select 'tr', 1
        assert_select 'tr.dir td.filename a', :text => 'subversion_test'
        assert_select 'tr.dir td.filename a[href=?]', "/projects/subproject1/repository/#{@repository.id}/show/subversion_test"
      end

      assert_select 'table.changesets tbody' do
        assert_select 'tr', 10
        assert_select 'tr td.id a', :text => '12'
      end

      assert_select 'input[name=rev]'
      assert_select 'a', :text => 'Statistics'
      assert_select 'a', :text => 'Atom'
      assert_select 'a[href=?]', "/projects/subproject1/repository/#{@repository.id}", :text => 'root'
    end

    def test_show_non_default
      Repository::Subversion.create(:project => @project,
        :url => self.class.subversion_repository_url,
        :is_default => false, :identifier => 'svn')
      get(
        :show,
        :params => {
          :id => PRJ_ID,
          :repository_id => 'svn'
        }
      )
      assert_response :success

      assert_select 'tr.dir a[href="/projects/subproject1/repository/svn/show/subversion_test"]'
      # Repository menu should link to the main repo
      assert_select '#main-menu a[href="/projects/subproject1/repository"]'
    end

    def test_browse_directory
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :show,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test'])[:param]
        }
      )
      assert_response :success

      assert_select 'table.entries tbody' do
        assert_select 'tr', 7
        assert_select 'tr.dir td.filename a', :text => '[folder_with_brackets]'
        assert_select 'tr.dir td.filename a', :text => 'folder'
        assert_select 'tr.file td.filename a', :text => '+.md'
        assert_select 'tr.file td.filename a', :text => '.project'
        assert_select 'tr.file td.filename a', :text => 'helloworld.c'
        assert_select 'tr.file td.filename a', :text => 'textfile.txt'
        assert_select 'tr.file td.filename a', :text => 'foo.js'
      end

      assert_select 'a.text-x-c', :text => 'helloworld.c'
    end

    def test_browse_at_given_revision
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :show,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test'])[:param],
          :rev => 4
        }
      )
      assert_response :success

      assert_select 'table.entries tbody' do
        assert_select 'tr', 5
        assert_select 'tr.dir td.filename a', :text => 'folder'
        assert_select 'tr.file td.filename a', :text => '.project'
        assert_select 'tr.file td.filename a', :text => 'helloworld.c'
        assert_select 'tr.file td.filename a', :text => 'helloworld.rb'
        assert_select 'tr.file td.filename a', :text => 'textfile.txt'
      end
    end

    def test_file_changes
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :changes,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
        }
      )
      assert_response :success

      assert_select 'table.changesets tbody' do
        assert_select 'tr', 3
        assert_select 'tr td.id a', :text => '6'
        assert_select 'tr td.id a', :text => '3'
        assert_select 'tr td.id a', :text => '2'
      end

      # svn properties displayed with svn >= 1.5 only
      if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
        assert_select 'ul li' do
          assert_select 'b', :text => 'svn:eol-style'
          assert_select 'span', :text => 'native'
        end
      end
    end

    def test_directory_changes
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :changes,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder'])[:param]
        }
      )
      assert_response :success
      assert_select 'table.changesets tbody' do
        assert_select 'tr', 8
        assert_select 'tr td.id a', :text => '13'
        assert_select 'tr td.id a', :text => '12'
        assert_select 'tr td.id a', :text => '10'
        assert_select 'tr td.id a', :text => '9'
        assert_select 'tr td.id a', :text => '7'
        assert_select 'tr td.id a', :text => '6'
        assert_select 'tr td.id a', :text => '5'
        assert_select 'tr td.id a', :text => '2'
      end
    end

    def test_entry
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
        }
      )
      assert_response :success
      assert_select 'h2 a', :text => 'subversion_test'
      assert_select 'h2 a', :text => 'helloworld.c'
    end

    def test_entry_should_show_other_if_too_big
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      # no files in the test repo is larger than 1KB...
      with_settings :file_max_size_displayed => 0 do
        get(
          :entry,
          :params => {
            :id => PRJ_ID,
            :repository_id => @repository.id,
            :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
          }
        )
        assert_response :success
        assert_equal 'text/html', @response.media_type
        assert_select 'p.nodata'
      end
    end

    def test_entry_should_display_images
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
        }
      )
      assert_response :success
      assert_select 'img[src=?]', "/projects/subproject1/repository/#{@repository.id}/raw/subversion_test/folder/subfolder/rubylogo.gif"
    end

    def test_entry_should_preview_audio
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'chords.mp3'])[:param]
        }
      )
      assert_response :success
      assert_select 'audio[src=?]', "/projects/subproject1/repository/#{@repository.id}/raw/subversion_test/folder/subfolder/chords.mp3"
    end

    def text_entry_should_preview_markdown
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'testfile.md'])[:param]
        }
      )
      assert_response :success
      assert_select 'div.wiki', :html => "<h1>Header 1</h1>\n\n<h2>Header 2</h2>\n\n<h3>Header 3</h3>"
    end

    def text_entry_should_preview_textile
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'testfile.textile'])[:param]
        }
      )
      assert_response :success
      assert_select 'div.wiki', :html => "<h1>Header 1</h1>\n\n\n\t<h2>Header 2</h2>\n\n\n\t<h3>Header 3</h3>"
    end

    def test_entry_at_given_revision
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
          :rev => 2
        }
      )
      assert_response :success
      # this line was removed in r3 and file was moved in r6
      assert_select 'td.line-code', :text => /Here's the code/
    end

    def test_entry_not_found
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
        }
      )
      assert_select 'p#errorExplanation', :text => /The entry or revision was not found in the repository/
    end

    def test_entry_download
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :raw,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
        }
      )
      assert_response :success
      assert_equal "attachment; filename=\"helloworld.c\"; filename*=UTF-8''helloworld.c", @response.headers['Content-Disposition']
    end

    def test_directory_entry
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :entry,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'folder'])[:param]
        }
      )
      assert_response :success
      assert_select 'h2 a', :text => 'subversion_test'
      assert_select 'h2 a', :text => 'folder'
    end

    # TODO: this test needs fixtures.
    def test_revision
      get(
        :revision,
        :params => {
          :id => 1,
          :repository_id => 10,
          :rev => 2
        }
      )
      assert_response :success

      assert_select 'ul' do
        assert_select 'li' do
          # link to the entry at rev 2
          assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/entry/test/some/path/in/the/repo', :text => 'repo'
          # link to partial diff
          assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/diff/test/some/path/in/the/repo'
        end
      end
    end

    def test_invalid_revision
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :revision,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :rev => 'something_weird'
        }
      )
      assert_response :not_found
      assert_select_error /was not found/
    end

    def test_invalid_revision_diff
      get(
        :diff,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :rev => '1',
          :rev_to => 'something_weird'
        }
      )
      assert_response :not_found
      assert_select_error /was not found/
    end

    def test_empty_revision
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      ['', ' ', nil].each do |r|
        get(
          :revision,
          :params => {
            :id => PRJ_ID,
            :repository_id => @repository.id,
            :rev => r
          }
        )
        assert_response :not_found
        assert_select_error /was not found/
      end
    end

    # TODO: this test needs fixtures.
    def test_revision_with_repository_pointing_to_a_subdirectory
      r = Project.find(1).repository
      # Changes repository url to a subdirectory
      r.update_attribute :url, (r.url + '/test/some')
      get(
        :revision,
        :params => {
          :id => 1,
          :repository_id => 10,
          :rev => 2
        }
      )
      assert_response :success

      assert_select 'ul' do
        assert_select 'li' do
          # link to the entry at rev 2
          assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/entry/path/in/the/repo', :text => 'repo'
          # link to partial diff
          assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/diff/path/in/the/repo'
        end
      end
    end

    def test_revision_diff
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      ['inline', 'sbs'].each do |dt|
        get(
          :diff,
          :params => {
            :id => PRJ_ID,
            :repository_id => @repository.id,
            :rev => 3,
            :type => dt
          }
        )
        assert_response :success
        assert_select 'h2', :text => /Revision 3/
        assert_select 'th.filename', :text => 'subversion_test/textfile.txt'
      end
    end

    def test_revision_diff_raw_format
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :diff,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :rev => 5,
          :format => 'diff'
        }
      )
      assert_response :success
      assert_equal 'text/x-patch', @response.media_type
      assert_equal 'Index: subversion_test/folder/greeter.rb', @response.body.split(/\r?\n/).first
    end

    def test_directory_diff
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      ['inline', 'sbs'].each do |dt|
        get(
          :diff,
          :params => {
            :id => PRJ_ID,
            :repository_id => @repository.id,
            :rev => 6,
            :rev_to => 2,
            :path => repository_path_hash(['subversion_test', 'folder'])[:param],
            :type => dt
          }
        )
        assert_response :success

        assert_select 'h2', :text => /2:6/
        # 2 files modified
        assert_select 'table.filecontent', 2
        assert_select 'table.filecontent thead th.filename', :text => 'greeter.rb'
        assert_select 'table.filecontent thead th.filename', :text => 'helloworld.rb'
      end
    end

    def test_annotate
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :annotate,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
        }
      )
      assert_response :success

      assert_select 'tr' do
        assert_select 'th.line-num a[data-txt=?]', '1'
        assert_select 'td.revision', :text => '4'
        assert_select 'td.author', :text => 'jp'
        assert_select 'td', :text => /stdio.h/
      end
      # Same revision
      assert_select 'tr' do
        assert_select 'th.line-num a[data-txt=?]', '2'
        assert_select 'td.revision', :text => ''
        assert_select 'td.author', :text => ''
      end
    end

    def test_annotate_at_given_revision
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      get(
        :annotate,
        :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :rev => 8,
          :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
        }
      )
      assert_response :success
      assert_select 'h2', :text => /@ 8/
    end

    def test_destroy_valid_repository
      @request.session[:user_id] = 1 # admin
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      assert_equal NUM_REV, @repository.changesets.count

      assert_difference 'Repository.count', -1 do
        delete(:destroy, :params => {:id => @repository.id})
      end
      assert_response :found
      @project.reload
      assert_nil @project.repository
    end

    def test_destroy_invalid_repository
      @request.session[:user_id] = 1 # admin
      @project.repository.destroy
      @repository =
        Repository::Subversion.
          create!(
            :project => @project,
            :url     => "file:///invalid"
          )
      @repository.fetch_changesets
      assert_equal 0, @repository.changesets.count

      assert_difference 'Repository.count', -1 do
        delete(:destroy, :params => {:id => @repository.id})
      end
      assert_response :found
      @project.reload
      assert_nil @project.repository
    end
  else
    puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
    def test_fake; assert true end
  end
end